Customize the validation error messages of validation.js in magento

点点圈 提交于 2019-12-12 10:16:57

问题


In my magento application the checkout page , will displays error message using validation.js file.

when i click to continue in the new billing address without entereing some value it displays error message as This is required field..

I want to change this message as its corresponding field name .

Instead of that error message i need to display as First name is a required field..

How can i do this ?

EDIT

this is the input box which is located in customer/widget/name.phtml as:

<input type="text" id="<?php echo $this->getFieldId('firstname')?>" name="<?php echo $this->getFieldName('firstname')?>" value="<?php echo $this->escapeHtml($this->getObject()->getFirstname()) ?>" title="<?php echo $this->getStoreLabel('firstname') ?>" maxlength="255" class="input-text validate-firstname" <?php echo $this->getFieldParams() ?> />

This is the output.


回答1:


You can create another class in your validation.js file something like validate-firstname and add something like this in your validation.js file

 ['validate-firstname', 'First name is required field.', function(v) {
            return !Validation.get('IsEmpty').test(v);
        }],

Search for this validate-alpha validation line and after put this code in your js file and add validate-firstname class in your firstname input field.




回答2:


Add new rule to Validation like below and use that class for input.created new rule required-entry-productids and add class required-entry-productids to input.

 Validation.add('required-entry-productids', "Select the atlest one item you would like to return.", function(v) {
            return !Validation.get('IsEmpty').test(v);
        });


来源:https://stackoverflow.com/questions/16557820/customize-the-validation-error-messages-of-validation-js-in-magento

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!