How to override a JQuery unobtrusive method without modifying jquery.validate.unobtrusive.min.js?
Tag : jquery , By : Sebastián Ucedo
Date : March 29 2020, 07:55 AM
Any of those help Overriding may happen when both functions are placed in global namespace. In case of jquery.validation.unobtrusive.js function onErrors is declared internally inside other function and cannot be replaced by declaring other function with the same name. Seems there is no way to alter that function without changing source code.
|
ASP.NET MVC 3 Unobtrusive Jquery Validate not showing custom error messages more than once
Date : March 29 2020, 07:55 AM
Hope that helps Probably this behavior depends on a known problem of the jQuery validation plugin: dynamically adding new validation rules for elements works just once! Further attempts are rejected because the plugin think they are a duplicated attempt to define the already defined rules. This is the reason why the $.validator.unobtrusive.parse doesn't work when you add newly created content (when for instance you add a new row to a collection of items). There is a patch for the $.validator.unobtrusive.parse that you might try to apply also to the revalidate function....but it is better to rewrite it from scratch in a different way. The revalidate function usse the validation plugin just to place at the right place all validation errors, then it tries to reset the state of the validation plugin. However, deleting the validator object from the form is not enough to cancel all job done since there is another object contained in the form.data('unobtrusiveValidation'), where form is a variable containing the form being validated...This data are not reset by the revalidate function...and CANNOT be reset since resetting them would cause the cancellation of ALL client side validation rules. {
id:id of the element in error
errors:array of strings errors associated to the element
}
htmlName.Replace('$', '_').Replace('.', '_').Replace('[', '_').Replace(']', '_');
name.replace(/[\$\[\]\.]/g, '_');
function remoteErrors(jForm, errors) {
//////////
function inner_ServerErrors(elements) {
var ToApply = function () {
for (var i = 0; i < elements.length; i++) {
var currElement = elements[i];
var currDom = $('#' + currElement.id);
if (currDom.length == 0) continue;
var currForm = currDom.parents('form').first();
if (currForm.length == 0) continue;
if (!currDom.hasClass('input-validation-error'))
currDom.addClass('input-validation-error');
var currDisplay = $(currForm).find("[data-valmsg-for='" + currElement.name + "']");
if (currDisplay.length > 0) {
currDisplay.removeClass("field-validation-valid").addClass("field-validation-error");
replace = $.parseJSON(currDisplay.attr("data-valmsg-replace")) !== false;
if (replace) {
currDisplay.empty();
$(currElement.errors[0]).appendTo(currDisplay);
}
}
}
};
setTimeout(ToApply, 0);
}
/////////
jForm.find('.input-validation-error').removeClass('input-validation-error');
jForm.find('.field-validation-error').removeClass('field-validation-error').addClass('field-validation-valid');
var container = jForm.find("[data-valmsg-summary=true]");
list = container.find("ul");
list.empty();
if (errors.length > 0) {
$.each(errors, function (i, ival) {
$.each(ival.errors, function (j, jval) {
$("<li />").html(jval).appendTo(list);
});
});
container.addClass("validation-summary-errors").removeClass("validation-summary-valid");
inner_ServerErrors(errors);
setTimeout(function () { jForm.find('span.input-validation-error[data-element-type]').removeClass('input-validation-error') }, 0);
}
else {
container.addClass("validation-summary-valid").removeClass("validation-summary-errors");
}
}
function clearErrors(jForm) {
remoteErrors(jForm, []);
}
|
Customize min and max error messages for jQuery unobtrusive validation
Tag : jquery , By : mikhaelrasputin
Date : March 29 2020, 07:55 AM
this one helps. After digging around a bit I found what I was looking for in the jQuery validate source code. In the full jQuery validate download there is a 'localization' folder. In this folder the default error messages are set for different languages. This is i.e. exactly what I am trying to do. I added the following code to my custom JavaScript validations file: $.extend($.validator.messages, {
min: 'Min some message {0}',
max: 'Max some message {0}'
});
|
jQuery unobtrusive validation in .NET MVC 3 - showing success checkmark
Date : March 29 2020, 07:55 AM
|
Add Error to JQuery Unobtrusive Validation Summary Without a Key
Date : March 29 2020, 07:55 AM
|