1

I have some forms that have inlined labels. I have some javascript (jQuery) that detects when focus has changed or when a user is entering text that changes the class so that the inlined label disappears and isn't blocking the user's view of their entered text.

The problem I'm having occurs when the browser autocompletes the form. None of the conditions below are triggered so I can't clear out the inlined label. How can I detect the fact that text has been entered via autocomplete so that I can clear the labels?

The js I'm using (from http://www.zurb.com/playground/inline-form-labels):

$( document ).ready(
    function()
    {
      $( "label.inlined + .input-text" ).each(
          function( type )
          {
            $( this ).focus( function()
            {
              $( this ).prev( "label.inlined" ).addClass( "focus" );
            } );
            $( this ).keypress(
                function()
                {
                  $( this ).prev( "label.inlined" ).addClass( "has-text" )
                      .removeClass( "focus" );
                } );
            $( this ).blur(
                function()
                {
                  if( $( this ).val() == "" )
                  {
                    $( this ).prev( "label.inlined" ).removeClass( "has-text" )
                        .removeClass( "focus" );
                  }
                } );
          } );
    } );

Thanks!

Bryan

Bryan Marble
  • 3,467
  • 5
  • 26
  • 29
  • Sounds similar to http://stackoverflow.com/questions/343192/why-does-the-javascript-onchange-event-not-fire-if-autocomplete-is-on . – kloffy Apr 22 '10 at 15:40
  • Have you tried adding a handler for "paste" to do the same as the one for "keypress"? – Pointy Apr 22 '10 at 15:41
  • By going to kloffy's link, it mentioned the jQuery `change` event (also mentioned by zincorp). That didn't seem to work for me. `paste` didn't work either. – Bryan Marble Apr 22 '10 at 18:35
  • You can found an answer here: http://stackoverflow.com/questions/1267149/how-to-detect-when-user-ignores-jquery-autocomplete-suggestions –  Mar 08 '12 at 20:51

1 Answers1

0

Have you tried the change event?

zincorp
  • 3,284
  • 1
  • 15
  • 18
  • change only fires on blur: "for the other element types the event is deferred until the element loses focus." http://api.jquery.com/change/ – jsims281 Jan 17 '12 at 11:34