Support » Plugin: Ninja Forms - The Easy and Powerful Forms Builder » Find focused input fields with jQuery

  • Resolved felixdorner

    (@felixdorner)


    Hey,

    I am running on Ninja Forms 3.0.27. I try to find input fields with jQuery based on whether they are focused or not. I approach this with the following script:

    $( 'input' ).on( 'focusin', function() {
      $(this).closest( '.field-wrap' ).addClass( 'focus' );    
    });
    
    $( 'input' ).on( 'focusout', function() {
      if ( $(this).val()=='')
        $(this).closest( '.field-wrap' ).removeClass( 'focus' );      
    });

    This used to work prior to Version 3. It is still working with own input fields I setup for testing outside a Ninja Form. Based on this I assume there is nothing wrong with the script itself. However I don’t get the script running inside a version 3 Ninja Form. The script simply don’t find the inputs inside a ninja form. Any ideas?

    • This topic was modified 2 years, 7 months ago by  felixdorner.
Viewing 1 replies (of 1 total)
  • Plugin Author klhall1987

    (@klhall1987)

    Hey Felix,

    Two things. One, they need to make sure that their code is in a jQuery(document).on(‘nfFormReady’) callback. This works like:

    $( document ).on( 'nfFormReady', function( e, layoutView )  {
        // Custom code can go here, knowing that the form has loaded.
    } );

    Two, make sure that the .field-wrap class they are targeting is present and where they expect.

    If this snippet doesn’t help get your issue resolved. You might want to join our developer slack community. Someone there might be able to help get you pointed in the right direction. I’ve linked to the page to join the community below.

    Ninja Forms Developer Slack Community:
    http://developer.ninjaforms.com/slack/

    Thanks,
    Kenny

Viewing 1 replies (of 1 total)
  • The topic ‘Find focused input fields with jQuery’ is closed to new replies.