jquery - How to set $jQval.unobtrusive.options ErrorPlacement function correclty -
what proper way override errorplacement function in jquery.validate.unobtrusive?
looking @ jquery.validate.unobtrusive.js script appears developers intention allow apply own errorplacement function setting $jqval.unobtrusive.options.
in validationinfo(form) function defines errorplacement function see call execincontext("errorplacement", arguments).
it seem if create errorplacement function under $.validator.unobtrusive.options called.
$.validator.unobtrusive.options = { errorplacement: function () { console.log("hello"); } };
the issue must configured after jquery.validate.js , before jquery.validate.unobtrusive.js referenced. otherwise $jqval.unobtrusive.options null , $form.data(data_validation, result) not set again.
function validationinfo(form) { var $form = $(form), result = $form.data(data_validation), onresetproxy = $.proxy(onreset, form), defaultoptions = $jqval.unobtrusive.options || {}, execincontext = function (name, args) { var func = defaultoptions[name]; func && $.isfunction(func) && func.apply(form, args); } if (!result) { result = { options: { // options structure passed jquery validate's validate() method errorclass: defaultoptions.errorclass || "input-validation-error", errorelement: defaultoptions.errorelement || "span", errorplacement: function () { onerror.apply(form, arguments); execincontext("errorplacement", arguments); }, invalidhandler: function () { onerrors.apply(form, arguments); execincontext("invalidhandler", arguments); }, messages: {}, rules: {}, success: function () { onsuccess.apply(form, arguments); execincontext("success", arguments); } }, attachvalidation: function () { $form .off("reset." + data_validation, onresetproxy) .on("reset." + data_validation, onresetproxy) .validate(this.options); }, validate: function () { // validation function called unobtrusive ajax $form.validate(); return $form.valid(); } }; $form.data(data_validation, result); } return result; }
the other way deal
set $.validator.unobtrusive.options error placement function
remove unobtrusive validation
re apply unobtrusive validation
$.validator.unobtrusive.options = { errorplacement: function () { console.log("errorplacement"); } }; $("#form_selector").removedata("unobtrusivevalidation"); // reapply form's validator $.validator.unobtrusive.parse(document);
or other option override function call.
var validator = $("#form_selector").data('validator'); var originalfunction = validator.settings.errorplacement; validator.settings.errorplacement = function(error,element) { console.log("errorplacement"); originalfunction(error, element); };
which proper way of implementing own errorplacement method?
Comments
Post a Comment