Skip to content

Instantly share code, notes, and snippets.

@adoc
Created February 14, 2015 06:29
Show Gist options
  • Save adoc/913da3bde1b86d45f733 to your computer and use it in GitHub Desktop.
Save adoc/913da3bde1b86d45f733 to your computer and use it in GitHub Desktop.
var formError = function (options) {
/*
options expected:
input_el - $selector for input field
error_el - $selector for error div
hide_error_duration - Duration in ms to hide the error.
hide_error_animation_duration - Jesus...
*/
var options = _.extend({}, options);
options.hide_error_duration = options['hide_error_duration'] || 2000;
options.hide_error_animation_duration = options['hide_error_animation_duration'] || 100;
var $input_el = $(options.input_el);
var $error_el = $(options.error_el);
var _timer = setTimeout(function () {
$error_el.hide({
duration: options.hide_error_animation_duration
});
}, options.hide_error_duration);
// Bind click quick hide
$error_el.one('click', function (event) {
event.preventDefault();
clearTimeout(_timer);
$error_el.hide();
$input_el.focus();
return false;
});
$error_el.show();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment