Form field reloaded stops form submitting correctly

84 views
Skip to first unread message

Gowrav Vishwakarma

unread,
Dec 8, 2012, 3:15:36 AM12/8/12
to agile-too...@googlegroups.com
Here is my simple code

if I comment bold line form submits okey but if I keep it all looks normal, the other dropdown populates very well but at the time of form submission it given Ajax error.

if($crud->form){

            $item_field=$crud->form->getElement('item_id');
            $rate_field=$crud->form->getElement('rate');
           
            if($_GET['changed_item']){
                $itm=$this->add('Model_Item_Inward');
                $q=$itm->dsql()->del('field')->field('DISTINCT(rate) collected_rate')->where('item_id',$_GET['changed_item']);
                $r_array=array();
                foreach($q as $junk){
                    $r_array += array($junk['collected_rate']=>$junk['collected_rate']);
                }
                $rate_field->setValueList($r_array);   
            }

            $item_field->js('change',$crud->form->js()->atk4_form('reloadField','rate',array($this->api->url(),'changed_item'=>$item_field->js()->val())));

        }

This type of error is giving problem on almost every where where we are using reloaded form field elements, we are on atk 4.2.2

Romans Malinovskis

unread,
Dec 8, 2012, 5:30:06 PM12/8/12
to agile-too...@googlegroups.com
just a guess, but when that reload request is happening, does it pass enough GET arguments to have a working Form object to respond to the query?

--
Join our IRC Support channel: http://irc.lc/freenode/atk4 or irc://irc.freenode.net/atk4 

Romans Malinovskis is the author of the revolutionary PHP Framework: the “Agile Toolkit” (www.agiletoolkit.org). Please show your support by raising awareness about Agile Toolkit.

If you need help with your commercial Agile Toolkit project, consider using our dev team: http://www.agiletech.ie/company/

--
 
 

Gowrav Vishwakarma

unread,
Dec 9, 2012, 11:59:11 PM12/9/12
to agile-too...@googlegroups.com
No, it is not working and problem is not this.
The problem is Model has a field which has setValueList on it with some predefined values.
if we populate the field with new values and submit the form it still try to get values from the initial set and throws exception that submitted value of the populated drop down is not from the offered list...

is there any workarround for this situation .. in CRUD.

Romans Malinovskis

unread,
Dec 10, 2012, 3:56:07 AM12/10/12
to agile-too...@googlegroups.com
  function validate(){
        if(!$this->value)return parent::validate();
        $this->getValueList(); //otherwise not preloaded?
        if(!isset($this->value_list[$this->value])){
            $this->form->errors[$this->short_name]="This is not one of the offered values";
        }
        return parent::validate();
    }


Somehow you should change that in your dropdown. You can extend the field

class Form_Field_MyDropdown extends Form_Field_DropDown {

  function validate(){
     if(!isset($this->value_list[$this->value])){
        $this->value_list[$this->value]=true;
     }
    return parent::validate();
  }
}


--
Join our IRC Support channel: http://irc.lc/freenode/atk4 or irc://irc.freenode.net/atk4 

Romans Malinovskis is the author of the revolutionary PHP Framework: the “Agile Toolkit” (www.agiletoolkit.org). Please show your support by raising awareness about Agile Toolkit.

If you need help with your commercial Agile Toolkit project, consider using our dev team: http://www.agiletech.ie/company/

--
 
 

Reply all
Reply to author
Forward
0 new messages