A few people have asked about automatically clearing the default field values on focus. While that’s not a feature in the current version of Gravity Forms, It’s easy enough to accomplish with a little bit of jQuery goodness. This script will remove any default value from input fields and textareas on focus, and if you haven’t changed it, will restore it on blur.
You can add the script below to your header.php file if you want it to be available for all of your forms, or can create a new page template, associate it with the page the form is on and include the script there. Note: This snippet requires that the jQuery library is already loaded in your theme to function properly.
The Script
<script type= "text/javascript" > |
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( ".clearit input, .clearit textarea" ).cleardefault(); |
}); |
</script> |
Defining the Fields
Once you’ve included the script in your page, it’s easy to define which fields you want to clear. Simply open up the form in the Gravity Forms admin, navigate to the field you want to clear, click on the Advanced tab and add the CSS Class Name “clearit“. Save the form and you’re good to go.
IF IT DOES NOT CLEAR, CHECK THE JQUERY LIBARY and REPLACE WITH THE FOLLOWING IN CURRENT CHILD THEME functions.php:
if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11); function my_jquery_enqueue() { wp_deregister_script('jquery'); wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false, null); wp_enqueue_script('jquery'); }