From dad0abe9b8e15dae4ca9a3af760e079ce8bfedb4 Mon Sep 17 00:00:00 2001 From: sync Date: Fri, 4 Oct 2024 20:11:57 +0300 Subject: [PATCH] Implement highlighting fields with error/warning values and focusing appropriate field on clicking on the error message. --- src/Form.jsx | 49 +++++++++++++++++++++++++++++++++++++++++++----- src/Messages.jsx | 2 ++ 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/Form.jsx b/src/Form.jsx index 677ca76..11d8e84 100644 --- a/src/Form.jsx +++ b/src/Form.jsx @@ -138,6 +138,25 @@ function Form() { }, ]; + const focusField = (fieldName) => { + document.getElementById(fieldName).focus(); + }; + + const getBorderColor = (fieldName) => { + try { + switch (messages[fieldName].status) { + case 'ERROR': + return 'red'; + case 'WARNING': + return 'orange'; + default: + return 'black'; + } + } catch { + return 'black'; + } + }; + const handleBlur = () => { setFirstRender(false); (async () => { @@ -244,9 +263,11 @@ function Form() {
setAmount(e.target.value)} onBlur={handleBlur} + style={{ borderColor: getBorderColor('amount') }} /> RUB @@ -282,10 +303,14 @@ function Form() {
БИК:
setBNFBankBic(e.target.value)} onBlur={handleBlur} - style={{ maxWidth: '32ch' }} + style={{ + maxWidth: '32ch', + borderColor: getBorderColor('bnf_bank_bic'), + }} />
№ Корр. счета:
@@ -306,19 +331,27 @@ function Form() {
ИНН:
setBNFINN(e.target.value)} onBlur={handleBlur} - style={{ maxWidth: '32ch' }} + style={{ + maxWidth: '32ch', + borderColor: getBorderColor('bnf_inn'), + }} />
КПП (103):
setBNFKPP(e.target.value)} onBlur={handleBlur} - style={{ maxWidth: '32ch' }} + style={{ + maxWidth: '32ch', + borderColor: getBorderColor('bnf_kpp'), + }} />
@@ -326,10 +359,14 @@ function Form() {
Наименование:
setBNFName(e.target.value)} onBlur={handleBlur} - style={{ width: '100ch' }} + style={{ + width: '100ch', + borderColor: getBorderColor('bnf_name'), + }} />
Банк получателя:
@@ -337,12 +374,14 @@ function Form() {
Назначение платежа: