I get this error message on a textbox field when I want to validate its form.
There is a requiredif validation attribute on this field, but this field is a clone of its original. I changed all properties of it and even its rules also copied.
C#:
JavaScript code for initializing the validation:
}
);
JavaScript code from clone method:
Unfortunately, I cannot find the error. Can anybody help me, please?
<strong>EDIT:</strong>
This line is missing from the cloe method:
<strong>EDIT2:</strong><br>
Now it works well.<br>
Thanks to this site:<br>
<a href="http://xhalent.wordpress.com/2011/02/08/copying-jquery-validation-from-one-element-to-another/" rel="nofollow">http://xhalent.wordpress.com/2011/02/08/copying-jquery-validation-from-one-element-to-another/</a>
There is a requiredif validation attribute on this field, but this field is a clone of its original. I changed all properties of it and even its rules also copied.
C#:
Code:
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;
for (int i = 0; i < valueLength; i++)
{
sb.Append(value[i].ToString());
if (i != utolsoElem)
{
sb.Append("|");
}
}
ValidationParameters.Add("value", sb.ToString().ToLower());
}
}
JavaScript code for initializing the validation:
Code:
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 from clone method:
Code:
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, I cannot find the error. Can anybody help me, please?
<strong>EDIT:</strong>
This line is missing from the cloe method:
Code:
rules['messages'] = $('form').data('validator').settings.messages["Cert[0].EndDate"];
<strong>EDIT2:</strong><br>
Now it works well.<br>
Thanks to this site:<br>
<a href="http://xhalent.wordpress.com/2011/02/08/copying-jquery-validation-from-one-element-to-another/" rel="nofollow">http://xhalent.wordpress.com/2011/02/08/copying-jquery-validation-from-one-element-to-another/</a>