2

In an custom admin form, I have added a custom tab and some custom fields to it. here I need to add field dependency for the fields as described below.

if the field zipbasedprice_isrange is set to yes, then I need to show other two fields & if it is set to no, then only one field should be shown. How can I implement this using below form?

Field dependencies should be between zipbasedprice_isrange, zipbasedprice_zip, zipbasedprice_zip_from_zip & zipbasedprice_zip_to_zip.

I tried default field dependencies, but it did not work. Help me, how to implement this using a javascript function?

  $isRange = $fieldset->addField('zipbasedprice_isrange', 'select', array(
    'name' => 'zipbasedprice_isrange',
    'label' => Mage::helper('zipbasedprice')->__('Is Range?'),
    'values' => array(
        array(
            'value' => false,
            'label' => Mage::helper('zipbasedprice')->__('No'),
        ),
        array(
            'value' => true,
            'label' => Mage::helper('zipbasedprice')->__('Yes'),
        )
    ),
   'value' => false,
   'onchange' => 'onIsZipRangeChange()',
   'required' => false,
   'style' => 'width:275px',
  ));


$fieldset->addField('zipbasedprice_zip', 'text', array(
    'name' => 'zipbasedprice_zip',
    'label' => Mage::helper('zipbasedprice')->__('Zip Code'),
    'class' => 'input',
    'required' => true,
    'style' => 'width:268px',
    'value' => '*',
    'maxlength' => 6,
 ));


 $fieldset->addField('zipbasedprice_zip_from_zip', 'text', array(
    'name' => 'zipbasedprice_zip_from_zip',
    'label' => Mage::helper('zipbasedprice')->__('Zip Code From'),
    'class' => 'input',
    'required' => true,
    'style' => 'width:268px',
    'value' => '*',
    'maxlength' => 6,
 ));

  $fieldset->addField('zipbasedprice_zip_to_zip', 'text', array(
    'name' => 'zipbasedprice_zip_to_zip',
    'label' => Mage::helper('zipbasedprice')->__('Zip Code To'),
    'class' => 'input',
    'required' => true,
    'style' => 'width:268px',
    'value' => '*',
    'maxlength' => 6,
 ));

1 Answer 1

3

I tried default field dependencies, but it did not work.

Do you mean you tried this dependency trick?

$this->setChild('form_after', $this->getLayout()
    ->createBlock('adminhtml/widget_form_element_dependence')
        ->addFieldMap('zipbasedprice_isrange', 'zipbasedprice_isrange')
        ->addFieldMap('zipbasedprice_zip', 'zipbasedprice_zip')
        ->addFieldMap('zipbasedprice_zip_from_zip', 'zipbasedprice_zip_from_zip')
        ->addFieldMap('zipbasedprice_zip_to_zip', 'zipbasedprice_zip_to_zip')
        ->addFieldDependence('zipbasedprice_zip', 'zipbasedprice_isrange', false)
        ->addFieldDependence('zipbasedprice_zip_from_zip', 'zipbasedprice_isrange', true)
        ->addFieldDependence('zipbasedprice_zip_to_zip', 'zipbasedprice_isrange', true)
);
1
  • Yes, I tried the same, field dependency code. I'm inheriting the class Mage_Adminhtml_Block_Widget and implementing class Mage_Adminhtml_Block_Widget_Tab_Interface, which contains both the form and grid in one page under a tab in edit product. Commented Aug 31, 2014 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.