Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

react prevent form submission on enter key press inside inputs

    // Prevent form submission on enter key press inside inputs
    const listener = e => {if(e.keyIdentifier==='U+000A'||e.keyIdentifier==='Enter'||e.keyCode===13){if(e.target.nodeName === 'INPUT' && e.target.type !== 'textarea'){e.preventDefault();return false;}}};
    document.addEventListener('keydown', listener, true);
 
PREVIOUS NEXT
Tagged: #react #prevent #form #submission #enter #key #press #inputs
ADD COMMENT
Topic
Name
1+4 =