4

i need to hide form field on on change in magento admin. I need to know that how can i show hide field with his labels in magento admin form my form

$fieldset->addField('style_content', 'select', array(
            'label' => Mage::helper('magazine')->__('Select available Slider Styles'),
            'name' => 'style_content',           
            'values' => array(
                array(
                    'value' => 'Yes',
                    'label' => Mage::helper('magazine')->__('Yes'),
                ),
                array(
                    'value' => 'No',
                    'label' => Mage::helper('magazine')->__('No'),
                ),
            ),
            'onchange'  => 'onchangeStyleShow()',
        ));
5

magento is provide to add JavaScript function on admin form using setAfterElementHtml where you can right your custom script.

$field->setAfterElementHtml('<script>
 function onchangeStyleShow(){
// here goes your custom Javascript
}
</script>');
4

Detail code using setAfterElementHtml:

// This is the field to hide
$fieldset->addField('field_to_hide', text, array(
    'label'  => $this->__('Test'),
));

// Select field
$styleContentField = $fieldset->addField('style_content', 'select', array(
            'label' => Mage::helper('magazine')->__('Select available Slider Styles'),
            'name' => 'style_content',           
            'values' => array(
                array(
                    'value' => 'Yes',
                    'label' => Mage::helper('magazine')->__('Yes'),
                ),
                array(
                    'value' => 'No',
                    'label' => Mage::helper('magazine')->__('No'),
                ),
            ),
            'onchange'  => 'onchangeStyleShow()',
        ));

// Javascript function to show/hide field_to_hide
$styleContentField->setAfterElementHtml('
                        <script>
                        function onchangeStyleShow() {                                              
                            $("field_to_hide").toggle()
                        }
                        </script>
                    ');

More details: Magento: Show/Hide Admin Form fields using Javascript

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.