Answers for "prevent input to enter string in react js"

2

capture enter button react input

const Enter = () => {
  	const handle = () => console.log('Enter pressed');
  
	return <input type="text" onKeyDown={e => e.key === 'Enter' && handle} />;
};
Posted by: Guest on February-11-2021
0

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);
Posted by: Guest on September-01-2021

Code answers related to "prevent input to enter string in react js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language