Skip to content

Instantly share code, notes, and snippets.

Created October 19, 2015 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/32c469005cbb15df3061 to your computer and use it in GitHub Desktop.
Save anonymous/32c469005cbb15df3061 to your computer and use it in GitHub Desktop.
Focus first text input on Bootstrap modal show
(function ($) {
var _original = $.fn.modal.Constructor.prototype.show;
function trigger(target, name, relatedTarget) {
target.trigger($.Event(name, { relatedTarget: relatedTarget }));
}
$.extend($.fn.modal.Constructor.prototype, {
show: function (_relatedTarget) {
var thisModal = this;
this.$element.one('shown.bs.modal', function() {
thisModal.$element.find('[type=text], [type=password]').first().focus();
});
return _original.call(this, _relatedTarget);
}
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment