From 96a91c4ad7aa503c2eb92a444f2edbb551a1b1a2 Mon Sep 17 00:00:00 2001 From: Mathias Bynens Date: Thu, 4 Feb 2010 16:21:34 +0100 Subject: [PATCH] Apply the click handler on the submit button instead of the entire form --- jquery.placeholder.js | 7 ++++--- jquery.placeholder.min.js | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/jquery.placeholder.js b/jquery.placeholder.js index 99d5ca1..2fb8109 100644 --- a/jquery.placeholder.js +++ b/jquery.placeholder.js @@ -21,10 +21,11 @@ }; }; // Submit handler on all forms containing input[placeholder] - $('form:has([placeholder])').click(function() { + // Needs to be via .click() + $('form:has([placeholder]) input[type=submit]').click(function() { // if ($(this).has('.placeholder') never returns false here — WTF? - if ($(this).find('.placeholder').length) { - $(this).find('.placeholder:first').val('').focus().removeClass('placeholder'); + if ($(this.form).find('.placeholder').length) { + $(this.form).find('.placeholder:first').val('').focus().removeClass('placeholder'); return false; }; }); diff --git a/jquery.placeholder.min.js b/jquery.placeholder.min.js index e55ffa5..05fc2f3 100644 --- a/jquery.placeholder.min.js +++ b/jquery.placeholder.min.js @@ -3,4 +3,4 @@ * @link http://github.com/mathiasbynens/Placeholder-jQuery-Plugin * @author Mathias Bynens */ -(function(a){a.fn.placeholder=function(){if(this[0]&&'placeholder' in document.createElement('input')){return this}function b(c){if(c.val()===''||c.val()===c.attr('placeholder')){c.addClass('placeholder').val(c.attr('placeholder'))}else{c.removeClass('placeholder')}}a('form:has([placeholder])').click(function(){if(a(this).find('.placeholder').length){a(this).find('.placeholder:first').val('').focus().removeClass('placeholder');return !1}});return a(this).each(function(){var c=a(this);if(c.is(':password')||!c.is(':input')){return}b(c);c.focusin(function(){if(c.val()===c.attr('placeholder')){c.val('').removeClass('placeholder')}}).focusout(function(){b(c)})})}})(jQuery); \ No newline at end of file +(function(a){a.fn.placeholder=function(){if(this[0]&&'placeholder' in document.createElement('input')){return this}function b(c){if(c.val()===''||c.val()===c.attr('placeholder')){c.addClass('placeholder').val(c.attr('placeholder'))}else{c.removeClass('placeholder')}}a('form:has([placeholder]) input[type=submit]').click(function(){if(a(this.form).find('.placeholder').length){a(this.form).find('.placeholder:first').val('').focus().removeClass('placeholder');return !1}});return a(this).each(function(){var c=a(this);if(c.is(':password')||!c.is(':input')){return}b(c);c.focusin(function(){if(c.val()===c.attr('placeholder')){c.val('').removeClass('placeholder')}}).focusout(function(){b(c)})})}})(jQuery); \ No newline at end of file