Last active
August 19, 2024 02:34
-
-
Save BronsonQuick/3495318 to your computer and use it in GitHub Desktop.
Clear default values in Gravity Forms and place them back in on blur if they are empty
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function($) { | |
jQuery.fn.cleardefault = function() { | |
return this.focus(function() { | |
if( this.value == this.defaultValue ) { | |
this.value = ""; | |
} | |
}).blur(function() { | |
if( !this.value.length ) { | |
this.value = this.defaultValue; | |
} | |
}); | |
}; | |
jQuery(".gform_wrapper input[type='text'], .gform_wrapper input[type='email'], .gform_wrapper input[type='tel'], .gform_wrapper input[type='search'], .gform_wrapper input[type='url'], .gform_wrapper input[type='number'], .gform_wrapper textarea").cleardefault(); | |
}); |
Thanks for the great snippet!
Yes, thanks! Works great.
How about the onfocus after form is submitted and not all required fields are filled out? Script doesn't work after that. Please advice
add this to the top makes it easier $('form li').addClass('clearit');
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Of course this should be enqueue in WordPress properly with a function in php such as: