2

How to add 2 or more validation in $fieldset when create. Example:

        $fieldset->addField(
        'tax_class_id',
        'select',
        [
            'name' => 'tax_class',
            'label' => __('Tax Class'),
            'title' => __('Tax Class'),
            'class' => 'required-entry',
            'required' => true,
            'values' => 'test',
        ]
    );

And how to know which is the first validation will check. Thanks all.

2
$fieldset->addField(
    'tax_class_id',
    'select',
    [
        'name' => 'tax_class',
        'label' => __('Tax Class'),
        'title' => __('Tax Class'),
        'class' => 'validate-email validate-digits required-entry', //add multiple classess
        'required' => true,
        'values' => 'test',
    ]
);

The class required-entry always gets first preference then validation is checked in order of classes added. You can try with validate-email validate-digits required-entry. This is reference for available classes.

2

You may to add new validations to 'class' element separated with gap. E.g.:

$fieldset->addField(
    'tax_class_id',
    'select',
    [
        'name' => 'tax_class',
        'label' => __('Tax Class'),
        'title' => __('Tax Class'),
        'class' => 'required-entry validate-email validate-digits',
        'required' => true,
        'values' => 'test',
    ]
);

More examples you may find in Magento forms, e.g. app\code\core\Mage\Adminhtml\Block\Permissions\User\Edit\Tab\Main.php

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.