JavaScript form validation ,which is lightweight and easy.
Rencently I need a form validation in some program having the same validate rules and style.I find parsley,which can validate the form data with same rules ,but it have different error styles and so complex.So,I decided to write a form validation to sovle the problems in these program.
using npm
npm install mvform --save
or using bower
bower install mvform --save
Setup your validation element, then invoke the function validate
,finally see errors
attribute ,which include all error message and element id
var mv = Object.create(MvForm);
mv.setup('#admin_form', {showError: true});
var result = mv.validate();
if (MvForm.isPrototypeOf(mv)) {
var errors = mv.errors;
for (var i = 0, j = errors.length; i < j; i++) {
$('#result').append($('<p>').text('元素ID:' + errors[i].id + ';错误消息:' + errors[i].msg))
}
}
More examlpes to see /examples
directory,introducing four way to use mvform
.
- base form validation
- define your own error message
- define your own error container element
- single element validation
I use the bootstrap as css framwork.The form is horizontal,the error message will append to the label.So,bootstrap is the best choice to use with mvform
.You can use mvform
just as form validation ,then writing your own css style based on the mvform
css style,which jsut define the error message style,see /src/mvform.css
.
I welcome contributions of all kinds from anyone.
Licensed under the MIT License