Implement validating form on pressing 'Enter' on input fields.

master
sync 1 year ago
parent f5e452438d
commit 7184ec126e

@ -149,6 +149,12 @@ function Form() {
}, },
]; ];
const handlePressEnter = (e, field = null) => {
if (e.key === 'Enter') {
handleBlur(field);
}
};
const focusField = (fieldName) => { const focusField = (fieldName) => {
document.getElementById(fieldName).focus(); document.getElementById(fieldName).focus();
}; };
@ -304,6 +310,7 @@ function Form() {
id="amount" id="amount"
value={amount} value={amount}
onChange={(e) => setAmount(e.target.value)} onChange={(e) => setAmount(e.target.value)}
onKeyDown={(e) => handlePressEnter(e)}
onBlur={handleBlur} onBlur={handleBlur}
style={{ borderColor: getBorderColor('amount') }} style={{ borderColor: getBorderColor('amount') }}
/> />
@ -345,6 +352,7 @@ function Form() {
value={bnfBankBic} value={bnfBankBic}
onChange={(e) => setBNFBankBic(e.target.value)} onChange={(e) => setBNFBankBic(e.target.value)}
onBlur={(e) => handleBlur('bnf_bank_bic')} onBlur={(e) => handleBlur('bnf_bank_bic')}
onKeyDown={(e) => handlePressEnter(e, 'bnf_bank_bic')}
style={{ style={{
maxWidth: '32ch', maxWidth: '32ch',
borderColor: getBorderColor('bnf_bank_bic'), borderColor: getBorderColor('bnf_bank_bic'),
@ -372,6 +380,7 @@ function Form() {
value={bnfAccount} value={bnfAccount}
onChange={(e) => setBNFAccount(e.target.value)} onChange={(e) => setBNFAccount(e.target.value)}
onBlur={(e) => handleBlur('bnf_account')} onBlur={(e) => handleBlur('bnf_account')}
onKeyDown={(e) => handlePressEnter(e, 'bnf_account')}
style={{ style={{
maxWidth: '32ch', maxWidth: '32ch',
borderColor: getBorderColor('bnf_account'), borderColor: getBorderColor('bnf_account'),
@ -385,6 +394,7 @@ function Form() {
value={bnfINN} value={bnfINN}
onChange={(e) => setBNFINN(e.target.value)} onChange={(e) => setBNFINN(e.target.value)}
onBlur={(e) => handleBlur('bnf_inn')} onBlur={(e) => handleBlur('bnf_inn')}
onKeyDown={(e) => handlePressEnter(e, 'bnf_inn')}
style={{ style={{
maxWidth: '32ch', maxWidth: '32ch',
borderColor: getBorderColor('bnf_inn'), borderColor: getBorderColor('bnf_inn'),
@ -398,6 +408,7 @@ function Form() {
value={bnfKPP} value={bnfKPP}
onChange={(e) => setBNFKPP(e.target.value)} onChange={(e) => setBNFKPP(e.target.value)}
onBlur={handleBlur} onBlur={handleBlur}
onKeyDown={(e) => handlePressEnter(e)}
style={{ style={{
maxWidth: '32ch', maxWidth: '32ch',
borderColor: getBorderColor('bnf_kpp'), borderColor: getBorderColor('bnf_kpp'),
@ -413,6 +424,7 @@ function Form() {
value={bnfName} value={bnfName}
onChange={(e) => setBNFName(e.target.value)} onChange={(e) => setBNFName(e.target.value)}
onBlur={handleBlur} onBlur={handleBlur}
onKeyDown={(e) => handlePressEnter(e)}
style={{ style={{
width: '91%', width: '91%',
borderColor: getBorderColor('bnf_name'), borderColor: getBorderColor('bnf_name'),
@ -428,6 +440,7 @@ function Form() {
value={paymentDetails} value={paymentDetails}
onChange={(e) => setPaymentDetails(e.target.value)} onChange={(e) => setPaymentDetails(e.target.value)}
onBlur={handleBlur} onBlur={handleBlur}
onKeyDown={(e) => handlePressEnter(e)}
style={{ style={{
height: '60px', height: '60px',
borderColor: getBorderColor('payment_details'), borderColor: getBorderColor('payment_details'),
@ -463,6 +476,7 @@ function Form() {
value={taxUINCode} value={taxUINCode}
onChange={(e) => setTaxUINCode(e.target.value)} onChange={(e) => setTaxUINCode(e.target.value)}
onBlur={handleBlur} onBlur={handleBlur}
onKeyDown={(e) => handlePressEnter(e)}
style={{ maxWidth: '32ch' }} style={{ maxWidth: '32ch' }}
/> />
</div> </div>

Loading…
Cancel
Save