• Resolved muzicutza81

    (@muzicutza81)


    Pressing the Enter key after entering a value in the Single Line Text field we have on our form currently resets the form instead of simulating a Next button click. Is there a way that I could trigger the closest Next button’s click event when pressing the Enter key while the cursor is still on the Single Line Text? Thanks!

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @muzicutza81,

    In the HTML standard if you press the enter key into an input field in a form, the form is submitted.

    An alternative to prevent this behavior:

    – Insert a “HTML Content” field in the form, and enter as its content, the following piece of code:

    
    <script>
    jQuery('[id*="cp_calculatedfieldsf_pform"] input').on('keypress', function(e) {
        return e.which !== 13;
    });
    </script>
    

    and that’s all.
    Best regards.

    Thread Starter muzicutza81

    (@muzicutza81)

    Thanks a bunch! Ended up using the following to simulate the Next button click also:

    <script>
    jQuery(‘[id*=”cp_calculatedfieldsf_pform”] input’).on(‘keypress’, function(e) {
    if (e.keyCode == 13)
    {
    jQuery(this).closest(‘.pbreak’).find(‘.pbNext’).click();
    return false;
    }
    else return e.keyCode;
    });
    </script>

    Plugin Author codepeople

    (@codepeople)

    Hello @muzicutza81,

    Excellent!!!!

    Thank you very much for sharing your solution.

    Best regards.

    danawilson171

    (@danawilson171)

    Thanks, all. The plugin has worked very well for my modest implementation. Here it is on the beta site. With all the suspect data in circulation, I thought it would be nice to have users change their own parameters and calculate the impacts of spay/neuter pets:

    https://beta2.snipfoundation.org/about-snip/

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Single Line Text enter key behavior’ is closed to new replies.