Search code examples
validationmagentoprototypejs

prototype js Validator


Is it possible in Validator plugin for prototypejs to put error-messages in certain div.class ?

I've tried

new Validation('.form-class', { containerClassName : '.other_div' })

but without any effect. Any ideas? Thx.


Solution

  • It doesn't look like the supplied validation allows for user-defined class names but it does use some predefined class names (see the "CSS Hooks" section).

    A quick look at the source shows this:

    getAdvice : function(name, elm) {
        return $('advice-' + name + '-' + Validation.getElmID(elm)) || $('advice-' + Validation.getElmID(elm));
    }
    

    So you can create some DIV elements in advance with an ID which the script will find and use. So if the password field is called password you can prepare an element like this:

    <div id="advice-password" class="other_div" style="display: hidden;"></div>
    

    If that's still not enough there is another possibility. Copy the /js/prototype/validation.js file to your theme's js folder (so the original remains intact) then in one of your theme's layout XML files do something like this:

    <default>
        <action method="removeItem"><type>js</type><name>prototype/validation.js</name></action>
        <action method="addItem"><type>skin_js</type><name>js/validation.js</name></action>
    </default>
    

    You are now free to modify the script however you want.