php - SilverStripe dependent dropdown - x is not a valid option -


i have simple dropdown field 2 values , dependent dropdown field:

public function areaform() {     $datasource = function($val) {         if ($val =='yes') {             $areas = dataobject::get('area', 'parentid = 0');             return $areas->map('id', 'name');         }         if ($val == 'no') {             return false;         }     };      $fields = new fieldlist(         textfield::create('name', 'area name:'),         $dropfield = dropdownfield::create('ischild', 'is sub area?', array('yes' => 'yes', 'no'=>'no' ))             ->setemptystring('select one'),         dependentdropdownfield::create('parentselect', 'select parent area:', $datasource)             ->setdepends($dropfield)             ->setemptystring('select one')     );      return new form($this, __function__, $fields, fieldlist::create(new formaction('dosavearea', 'save area'))); }  public function dosavearea($data, $form) {     var_dump($data);     exit;     $name = $data['name'];     $ischild = $data['ischild'];      if ($ischild === 'no') {         $area = new area();         $area->name = $name;         $area->parentid = 0;         $area->write();     }     elseif ($ischild === 'yes') {         $area = new area();         $area->name = $name;         $area->parentid = $data['parentselect'];         $area->write();     }     $this->redirectback(); } 

when ever try save object submitting form, gives me same message:

please select value within list provided. x not valid option

the values being populated correctly. can see them in browser inspecting element. yet if select id 1 example says "1 not valid option" etc each area object. gets stuck @ validation, doesn't go action. i've done similar things in other parts of site/other sites , work fine.

why validation incorrectly blocking form submission , how fix this?

seems need create array of map object.

if ($val =='yes') {     $areas = area::get()->filter('parentid', '0');     return $areas->map('id', 'name')->toarray(); } 

normally use map object source dropdownfield. think dependentdropdownfield has little trouble map object.


Comments