I am not so familiar with magento so i am facing some trouble
I am creating a form in magento admin & trying to add depended form field
eg- parent field is dropdown type & name is amount_type
options are flat_option
& percentage_option
child field are text type having name flat_value
& percentage_value
So my requirment flat_value
& percentage_value
are hidden at first after that if i select flat_option
in amount_type
then show flat_value
& in select percentage_option
then show percentage_option
.
my tried code is
$fieldset->addField('amount_type', 'select', array(
'name' => 'amount_type',
'label' => Mage::helper('adminhtml')->__('Amount Type'),
'title' => Mage::helper('adminhtml')->__('Amount Type'),
'class' => '',
'required' => true,
'value' => '1',
'values' => array('-1'=>'Please Select','1' => 'flat_option', '2' => 'percentage_option'),
)
);
$fieldset->addField('flat_value', 'text', array(
'name' => 'flat_value',
'label' => Mage::helper('adminhtml')->__('flat amount'),
'title' => Mage::helper('adminhtml')->__('flat amount'),
'class' => 'validate-number',
'required' => true,
)
);
$fieldset->addField('percentage_value', 'text', array(
'name' => 'percentage_value',
'label' => Mage::helper('adminhtml')->__('Percentage amount'),
'title' => Mage::helper('adminhtml')->__('Percentage amount'),
'class' => 'validate-number validate-digits-range digits-range-0-100',
'required' => true,
)
);
$this->setChild('form_after', $this->getLayout()
->createBlock('adminhtml/widget_form_element_dependence')
->addFieldMap('amount_type', 'amount_type')
->addFieldMap('flat_value', 'flat_value)
->addFieldDependence('flat_value', 'amount_type', 1)
);
$this->setChild('form_after', $this->getLayout()
->createBlock('adminhtml/widget_form_element_dependence')
->addFieldMap('amount_type', 'amount_type')
->addFieldMap('percentage_value', 'percentage_value')
->addFieldDependence('percentage_value', 'amount_type', 2)
);
Tanks in advance for help