Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Gravity Forms labels used as placeholders
jQuery(document).ready(function($){
// gravity forms custom placeholders
$('#inner li.gfield .gfield_label').click(function(){
$(this).next('.ginput_container').find('input[type="text"], textarea').focus();
})
$('#inner .ginput_container input[type="text"], #inner .ginput_container textarea')
.focus(function(){
$(this).closest('.ginput_container').prev('.gfield_label').hide();
})
.blur(function(){
if( $(this).val() == "" ){
$(this).closest('.ginput_container').prev('.gfield_label').show();
}
})
$('#inner .ginput_container input[type="text"], #inner .ginput_container textarea').each(function(){
if( $(this).val() != "" ){
$(this).closest('.ginput_container').prev('.gfield_label').hide();
}
})
});
#inner .gfield_label { }
#inner li.gfield { position:relative; }
#inner li.gfield .gfield_label { position:absolute; top: 4px; left: 6px; font-size: 14px; color: #949494; font-weight: normal; margin: 0; }
@mbootsman

This comment has been minimized.

Copy link

mbootsman commented Nov 7, 2013

Thanks for this Bill.
Here is revised code for using with Genesis 2.0 with HTML5 enabled.

jQuery(document).ready(function($){

    // gravity forms custom placeholders
    $('.site-inner li.gfield .gfield_label').click(function(){
        $(this).next('.ginput_container').find('input[type="text"], textarea').focus();
    });

    $('.site-inner .ginput_container input[type="text"], .site-inner .ginput_container textarea')
    .focus(function(){
        $(this).closest('.ginput_container').prev('.gfield_label').hide();
    })
    .blur(function(){
        if( $(this).val() === "" ){
            $(this).closest('.ginput_container').prev('.gfield_label').show();
        }
    });

    $('.site-inner .ginput_container input[type="text"], .site-inner .ginput_container textarea').each(function(){
        if( $(this).val() !== "" ){
            $(this).closest('.ginput_container').prev('.gfield_label').hide();
        }
    });

});

and the CSS

.site-inner .gfield_label {  }
.site-inner li.gfield  { position:relative;  }
.site-inner li.gfield .gfield_label { position:absolute; top: 4px; left: 6px; font-size: 14px; color: #949494; font-weight: normal; margin: 0; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.