最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Extend validation.js and validate single elements - Stack Overflow

programmeradmin1浏览0评论

Is it possible in Magento to extend validation.js to add the ability to validate single elements as opposed to plete forms.

If it is not possible what is the most unobtrusive way of customizing the validation.js script

Is it possible in Magento to extend validation.js to add the ability to validate single elements as opposed to plete forms.

If it is not possible what is the most unobtrusive way of customizing the validation.js script

Share Improve this question asked Aug 6, 2012 at 18:37 Marty WallaceMarty Wallace 35.8k57 gold badges143 silver badges209 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 10

Based more on the detail provided in the ment to Francesco than the initial question - If validation is required validation for individual form elements onblur then you need to set the 'immediate' property of the Validation object to true like so...

Validation.defaultOptions.immediate = true;

This will cause validation to occur if an elements value has been changed and it looses focus.

I take it this is a site wide change - so I would normally place code such as this my themes js file but alternatively you can also place it in a template (obviously before your form object gets initialised) by enclosing it in script tags i.e..

<script type="text/javascript">
    Validation.defaultOptions.immediate = true;
<script>

Create a CMS Block with a content like below, and add a Widget setting the Checkout page.

<script type="text/javascript">
    $$('.validate-michael-jackson').first().observe('blur', function(elem){
        if (elem.value == 'Michael Jackson') {
            alert('Come on baby! Are you really Michael Jackson?');
        }
    });
</script>

take a look at this : Link

By what I remember you can easly add a new validation in your .phtml files by extending validation.js class

发布评论

评论列表(0)

  1. 暂无评论