我想重置表单的验证而不清理数据(form.reset())。我正在使用FormValidator(http://www.formvalidator.net/)。
这个验证器使用表单的重置方法,但我不想清理输入数据,我只想删除红色边框和错误消息。
http://www.formvalidator.net/#configuration_setup
// Reset form using jQuery
$('#container form').get(0).reset();
谢谢
我复制了表单验证器的重置功能。
//CIRO : Its a copy of the JS without the element errorMessageCustom
var configReset = {
ignore: [], // Names of inputs not to be validated even though node attribute containing the validation rules tells us to
errorElementClass: 'error', // Class that will be put on elements which value is invalid
borderColorOnError: '#b94a48', // Border color of elements which value is invalid, empty string to not change border color
errorMessageClass: 'form-error', // class name of div containing error messages when validation fails
validationRuleAttribute: 'data-validation', // name of the attribute holding the validation rules
validationErrorMsgAttribute: 'data-validation-error-msg', // define custom err msg inline with element
errorMessagePosition: 'element', // Can be either "top" or "element" or "custom"
errorMessageTemplate: {
container: '<div class="{errorMessageClass} alert alert-danger">{messages}</div>',
messages: '<strong>{errorTitle}</strong><ul>{fields}</ul>',
field: '<li>{msg}</li>'
},
scrollToTopOnError: true,
dateFormat: 'yyyy-mm-dd',
addValidClassOnAll: false, // whether or not to apply class="valid" even if the input wasn't validated
decimalSeparator: '.',
inputParentClassOnError: 'has-error', // twitter-bootstrap default class name
inputParentClassOnSuccess: 'has-success', // twitter-bootstrap default class name
validateHiddenInputs: false // whether or not hidden inputs should be validated
}
//you can search the code with the text "reset.validation" at the "jquery.form-validator.js"
function resetValidation(idForm){
$elems1 = $("#"+idForm).find('.' + 'error' + ',.valid');
$("#"+idForm).find('.' + 'error' + '.alert').remove();
$.formUtils.errorDialogs.removeErrorStyling($elems1, configReset);
}
此代码是紧急的,可以改进