jquery - Warning: No message defined for -
i error message on textbox field when want validate form. there requiredif validation attribute on field, field clone of original. changed properties of , rules copied.
c#:
public class modelclientvalidationrequiredifrule : modelclientvalidationrule { public modelclientvalidationrequiredifrule(string errormessage, string otherproperty, comparison comparison, object[] value) { errormessage = errormessage; validationtype = "requiredif"; validationparameters.add("other", otherproperty); validationparameters.add("comp", comparison.tostring().tolower()); stringbuilder sb = new stringbuilder(); int valuelength = value.length; int utolsoelem = valuelength - 1; (int = 0; < valuelength; i++) { sb.append(value[i].tostring()); if (i != utolsoelem) { sb.append("|"); } } validationparameters.add("value", sb.tostring().tolower()); } }
javascript code initializing validation:
jquery.validator.unobtrusive.adapters.add("requiredif", ["other", "comp", "value"], function (options) { options.rules['requiredif'] = { other: options.params.other, comp: options.params.comp, value: options.params.value }; if (options.message) { options.messages['requiredif'] = options.message; }
} );
javascript code clone method:
thisraw.prev().find("td:eq(1) input") .attr("id", "cert_" + numofcer + "__enddate") .attr("name", "cert[" + numofcer + "].enddate") .attr("data-val-requiredif-other", "cert[" + numofcer + "].bizonyitvanyfajta"); var rules = $('form').find('#cert_0__enddate').rules(); rules['messages'] = $('form').data('validator').settings.messages["cert[0].enddate"]; thisraw.prev().find("td:eq(1) input").rules("add", rules); thisraw.prev().find("td:eq(1) span").attr("data-valmsg-for", "cert[" + numofcer + "].enddate"); $("#cert_" + numofcer + "__startdate").removeclass("hasdatepicker"); $("#cert_" + numofcer + "__enddate").removeclass("hasdatepicker"); createdynamicdatepicker(numofcer);
unfortunately, cannot find error. can me, please?
edit: line missing cloe method:
rules['messages'] = $('form').data('validator').settings.messages["cert[0].enddate"];
edit2:
works well.
site:
http://xhalent.wordpress.com/2011/02/08/copying-jquery-validation-from-one-element-to-another/
i've come across this. way override jquery validation. got due not providing message custom validation.
var errormessage = "something"; jquery.validator.addmethod("rulename", function(value, element, errormessage){ //code validate, return bool });
and in markup add class "rulename" attribute
<input id="someinput" class="rulename"></input>
both ways valid.
also, mark answer correct other users can find post answered.
Comments
Post a Comment