2

I have a custom grid in Admin panel. When you want to edit entries to the grid it will load a form. The required field validations of this form are not working. I have define the fields as below.

$fieldset->addField('discount', 'text', array(
                'label'    => $helper->__('Discount Amount (%)'),
                'required' => true,
                'class'    => 'required-entry',
                'name'     => 'discount',
                'index'    => 'discount',
        ));

Adding below two attributes not working. It saves even if the fields are empty.

'required' => true,
'class'    => 'required-entry',

Am I missing something else here?

  • Using the class "required-entry" should be sufficient to get the client side validation working. Do you see any JS errors? – mkerstner Aug 31 '15 at 9:22
  • there's no any JS errors. It just doesn't validate – Sukeshini Aug 31 '15 at 9:24
3

The form should be instantiated as a Varien_Form for validation to kick in. Find the ID of the form you are missing validation on, and add a little piece of Javascript to instantiate it as a Varien_Form:

<script type="text/javascript">
    //< ![CDATA[
        var myForm = new varienForm('myFormId');
    //]]>
</script>

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.