This post is written to help you understand better the method of validating the inputs in DOM without form.
While start constructing new pages in Magento, form validation is a necessary process which unfortunately is also highly repetitive. Luckily, Magento already comes with an in-built provision to form validation functions written in JavaScript.
Note: We can’t achieve form validation in Nested forms ( form inside form ) instead we can use this methodology.
Why and How
In some case we need to validate one or more field without form and form submit, in such situations can use validate method in js/prototype/validation.js
Validation.validate( );
Also you can find the methods & validation rules and their error message on your own by looking in js/prototype/validation.js on line 414
For instance, we will create a input to validate email and set email validation rule to it.
and here is the script to validate field
/* Sample function fo validate the single field */ function customValidate(){ if( Validation.validate( document.getElementById('email') ) ) { // Do something on success } else { return false; } }
that brings us to the end of this tech blog on how to validate input fields without forms in Magento.
Feel free to post your doubts and queries in comments section.
Leave a Reply