39 lines
994 B
JavaScript
39 lines
994 B
JavaScript
|
(function($){
|
||
|
$.fn.applyModelErrors = function(errorMessage, errorData) {
|
||
|
var $this = this;
|
||
|
|
||
|
if (errorMessage !== null) {
|
||
|
$this.find(".error-summary").first().text(errorMessage).show();
|
||
|
}
|
||
|
|
||
|
$.each(errorData, function(inputFieldName, value) {
|
||
|
var $input = $this.find("input[name='" + inputFieldName + "']");
|
||
|
if ($input.length > 1) {
|
||
|
$input = $("#" + inputFieldName);
|
||
|
}
|
||
|
|
||
|
if ($input.length === 1) {
|
||
|
if ($input[0].localName === "INPUT") {
|
||
|
$input.addClass("input-validation-error");
|
||
|
}
|
||
|
|
||
|
$("<span/>")
|
||
|
.addClass("field-validation-error")
|
||
|
.append($("<span/>").addClass("error-icon"))
|
||
|
.append($("<span/>").text(value))
|
||
|
.insertAfter($input);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
$.fn.clearModelErrors = function() {
|
||
|
this
|
||
|
.find(".field-validation-error").remove().end()
|
||
|
.find(".input-validation-error").removeClass("input-validation-error").end()
|
||
|
.find(".error-summary").empty().hide();
|
||
|
|
||
|
return this;
|
||
|
};
|
||
|
}(jQuery));
|