Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Clear default values in Gravity Forms and place them back in on blur if they are empty
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();
});
@BronsonQuick

This comment has been minimized.

Copy link
Owner Author

@BronsonQuick BronsonQuick commented Aug 28, 2012

Of course this should be enqueue in WordPress properly with a function in php such as:

@DevinWalker

This comment has been minimized.

Copy link

@DevinWalker DevinWalker commented Feb 22, 2013

Thanks for the great snippet!

@CatherineEng

This comment has been minimized.

Copy link

@CatherineEng CatherineEng commented Jan 14, 2014

Yes, thanks! Works great.

@goeiezaak

This comment has been minimized.

Copy link

@goeiezaak goeiezaak commented Aug 20, 2014

How about the onfocus after form is submitted and not all required fields are filled out? Script doesn't work after that. Please advice

@bort84

This comment has been minimized.

Copy link

@bort84 bort84 commented Feb 19, 2015

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