Making magento admin field dependent on more than one value or field? -


first of have seen question can magento adminhtml field depend on more 1 field or value? talks system/configuration fields, not looking for.

i trying create form in magento backend. have dropdown dropdown values 1, 2 , 3. need field x displayed when select 1 or 2. how do ?

i able display x depending on single value of dropdown, not multiple values.

this how have done:

$this->setchild('form_after',$this->getlayout()->createblock('adminhtml/widget_form_element_dependence')             ->addfieldmap($x->gethtmlid(), $xl->getname())             ->addfieldmap($dropdown->gethtmlid(), $dropdown->getname())             ->addfielddependence($x->getname(), $dropdown->getname(), 1) ); 

where $x , $dropdown variables stores addfield() result

you can.

more fields:
add more dependency:

->addfielddependence($x->getname(), $dropdown_1->getname(), $value_dw_1) ->addfielddependence($x->getname(), $dropdown_2->getname(),$value_dw_2) 

more values (same field):
should pass array of of values:

->addfielddependence($x->getname(), $dropdown->getname(), array($value1,value2)) 

if $value1/$value2 numbers better cast them string or not work properly:

->addfielddependence($x->getname(), $dropdown->getname(), array((string)$value1,(string)value2)) 

there reason issue can tracked down in js/mage/adminhtml/form.js in method trackchange @ 1 point see code :

... // define whether target should show     var shouldshowup = true;     (var idfrom in valuesfrom) {         var = $(idfrom);         if (valuesfrom[idfrom] instanceof array) {             if (!from || valuesfrom[idfrom].indexof(from.value) == -1) {                 shouldshowup = false;             }         } else {             if (!from || from.value != valuesfrom[idfrom]) {                 shouldshowup = false;             }         }     } .... 

you see in case valuesfrom[idfrom] used indexof check if show field or not, cause problem because, think, indexof comparison taking care of type , from.value contains string while in array valuesfrom[idfrom] have array of numbers ...

this issue not occur in case of single value because from.value != valuesfrom[idfrom] not taking care of type


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -