From 9a40898e11e9b06b1e9a73d879d6f768a9fce2ea Mon Sep 17 00:00:00 2001 From: Lvyshnevska Date: Thu, 9 May 2024 14:02:47 +0200 Subject: [PATCH] optional chaining, onblur to texfield --- .../ProfilePage/FormComponents/GeneralInfo.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/FrontEnd/src/components/ProfilePage/FormComponents/GeneralInfo.js b/FrontEnd/src/components/ProfilePage/FormComponents/GeneralInfo.js index bcc4d0f08..967c2c416 100644 --- a/FrontEnd/src/components/ProfilePage/FormComponents/GeneralInfo.js +++ b/FrontEnd/src/components/ProfilePage/FormComponents/GeneralInfo.js @@ -102,7 +102,7 @@ const GeneralInfo = (props) => { let isValid = true; const newFormState = {}; for (const key in profile) { - if (key in ERRORS && (!profile[key] || (Array.isArray(profile[key]) && profile[key].length === 0))) { + if (key in ERRORS && (!profile[key] || (Array.isArray(profile[key]) && profile[key]?.length === 0))) { isValid = false; newFormState[key] = { 'error': true, @@ -116,10 +116,10 @@ const GeneralInfo = (props) => { } } setFormStateErr({ ...formStateErr, ...newFormState }); - if (profile.official_name.length !== 0 && profile.official_name.length < 2) { + if (profile.official_name?.length !== 0 && profile.official_name?.length < 2) { isValid = false; } - if (profile.name.length < 2) { + if (profile.name?.length < 2) { isValid = false; } if (profile.edrpou) { @@ -147,7 +147,7 @@ const GeneralInfo = (props) => { const onUpdateField = e => { const { value: fieldValue, name: fieldName } = e.target; - const symbolCount = (fieldValue.replace(/[\s]/g,'')).length; + const symbolCount = (fieldValue.replace(/[\s]/g,''))?.length; setFormStateErr({ ...formStateErr, [fieldName]: {'error': false, 'message': ''}}); if (fieldName === 'name' && symbolCount < 2) { setFormStateErr({ ...formStateErr, [fieldName]: {'error': true, 'message': 'Введіть від 2 до 100 символів'}}); @@ -220,7 +220,7 @@ const GeneralInfo = (props) => { }; const onUpdateTextAreaField = e => { - if (e.target.value.length <= TEXT_AREA_MAX_LENGTH) + if (e.target.value?.length <= TEXT_AREA_MAX_LENGTH) setProfile((prevState) => { return { ...prevState, [e.target.name]: e.target.value }; }); @@ -491,6 +491,7 @@ const GeneralInfo = (props) => { name="common_info" label={LABELS.common_info} updateHandler={onUpdateTextAreaField} + onBlur={onBlurHandler} value={profile.common_info ?? ''} maxLength={TEXT_AREA_MAX_LENGTH} />