1

I am implementing one module. I have form fields like

 $fieldset->addField(
            'date_enabled', 'select', array(
                'label'     => Mage::helper('slider')->__('Use Date Range'),
                'name'      => 'date_enabled',
                'values'    => array(
                    0 => Mage::helper('slider')->__('No'),
                    1 => Mage::helper('slider')->__('Yes'),
                ),
            )
        );

  $fieldset->addField(
            'from_date', 'date', array(
                'name' => 'from_date',
                'label' => Mage::helper('slider')->__('From Date & Time'),
                'title' => Mage::helper('slider')->__('From Date & Time'),
                'image' => $this->getSkinUrl('images/grid-cal.gif'),
                'class' => 'validate-date',
                'time' => true,
                'input_format' => Varien_Date::DATETIME_INTERNAL_FORMAT,
                'format' => $dateFormatIso
            )
        );

        $fieldset->addField(
            'to_date', 'date', array(
                'name' => 'to_date',
                'label' => Mage::helper('slider')->__('To Date & Time'),
                'title' => Mage::helper('slider')->__('To Date & Time'),
                'image' => $this->getSkinUrl('images/grid-cal.gif'),
                'class' => 'validate-date',
                'time' => true,
                'input_format' => Varien_Date::DATETIME_INTERNAL_FORMAT,
                'format' => $dateFormatIso,
                'note'      =>$note,
            )
        );

what I want to do is if I select yes from 'Use Date Range'

Then only we can see fields 'From Date & Time' and 'To Date & Time' Otherwise, those fields are hidden.

How to do that in Magento 1.9.

4

You need to create Dependancy between these two fields.

for that add following code into your form

$this->setChild('form_after', $this->getLayout()
            ->createBlock('adminhtml/widget_form_element_dependence')
            ->addFieldMap('date_enabled','date_enabled')
            ->addFieldMap('from_date','from_date')
            ->addFieldMap('to_date','to_date')
            ->addFieldDependence('from_date','date_enabled',1)
            ->addFieldDependence('to_date','date_enabled',1)

              );

This works. And don't need to add javascript for that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.