Skip to content

Instantly share code, notes, and snippets.

@duskohu
Created December 9, 2013 20:57
Show Gist options
  • Save duskohu/7880740 to your computer and use it in GitHub Desktop.
Save duskohu/7880740 to your computer and use it in GitHub Desktop.
Custom netteForms.js - change alert messages
/**
* Display error message.
*/
Nette.addError = function (elem, message) {
if (elem.focus) {
elem.focus();
}
if (message) {
var elemPosition = $(elem).position();
var elmHeight = $(elem).outerHeight();
var alertMessage = $('<p/>');
alertMessage.addClass('help-inline');
alertMessage.html(message);
alertMessage.css({
left: elemPosition.left + "px",
'margin-top': 10 + "px"
});
var findAllError = $(".error p.help-inline");
findAllError.closest('.error').removeClass('error');
findAllError.remove();
if ($(elem).closest('.control-group').length > 0) {
$(elem).closest('.control-group').addClass('error');
} else {
$(elem).parent().addClass('error');
}
$(elem).after(alertMessage);
}
};
(function ($, undefined) {
$.nette.ext({
load: function () {
$(".error p.help-inline, p.help-inline.error").each(function (index) {
var elemPosition = $(this).prev().position();
//var elmHeight = $(this).prev().outerHeight();
$(this).css({
left: elemPosition.left + "px",
'margin-top': 10 + "px"
});
$(this).prev().focus();
});
$(window).keypress(function (e) {
var findAllError = $(".error p.help-inline, p.help-inline.error");
findAllError.fadeOut('slow', function () {
if (findAllError.closest('.control-group').length > 0) {
findAllError.closest('.control-group').removeClass('error');
}
findAllError.remove();
});
});
$(window).mouseup(function (e) {
var findAllError = $(".error p.help-inline, p.help-inline.error");
findAllError.fadeOut('slow', function () {
if (findAllError.closest('.control-group').length > 0) {
findAllError.closest('.control-group').removeClass('error');
}
findAllError.remove();
});
});
}
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment