From a3b9ab0d2512a26ce4ab5a18819f0629dc413112 Mon Sep 17 00:00:00 2001 From: Vitalii Kiiko Date: Tue, 22 Oct 2024 16:07:38 +0200 Subject: [PATCH 1/2] - added validation for some settings releated to form fields; --- .../FormField/components/NumberInput/index.js | 9 +++++---- .../components/ElementSetting/index.js | 7 +++++++ .../components/BuilderElementSettings/index.js | 16 +++++++++++++--- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/components/FormField/components/NumberInput/index.js b/src/components/FormField/components/NumberInput/index.js index 896fc32..d5d4ee4 100644 --- a/src/components/FormField/components/NumberInput/index.js +++ b/src/components/FormField/components/NumberInput/index.js @@ -1,8 +1,9 @@ import React from 'react'; import { classNames } from 'primereact/utils'; import { Controller } from 'react-hook-form'; -import { InputNumber } from 'primereact/inputnumber'; +import { is } from 'ramda'; +import { InputNumber } from 'primereact/inputnumber'; const NumberInput = ({ fieldName, @@ -25,7 +26,7 @@ const NumberInput = ({ const input = ( )}/> return ( diff --git a/src/pages/BandoFormsEdit/components/BuilderElementSettings/components/ElementSetting/index.js b/src/pages/BandoFormsEdit/components/BuilderElementSettings/components/ElementSetting/index.js index ca6d5d7..6264b89 100644 --- a/src/pages/BandoFormsEdit/components/BuilderElementSettings/components/ElementSetting/index.js +++ b/src/pages/BandoFormsEdit/components/BuilderElementSettings/components/ElementSetting/index.js @@ -64,6 +64,13 @@ const ElementSetting = ({ setting, changeFn, updateDataFn }) => { onTextChange={(e) => changeFn(e.htmlValue, setting.name)} style={{ height: 80 * 4 }} /> + } else if (setting.name === 'step') { + return changeFn(e.target.value, setting.name)}/> } else if (setting.name === 'table_columns') { return { const [activeElementData, setActiveElementData] = useState({}); const [settings, setSettings] = useState([]); const [validators, setValidators] = useState({}); - const textBasedValidatorFields = ['min', 'max', 'minLength', 'maxLength', 'pattern']; + const numberBasedValidatorFields = ['min', 'max', 'minLength', 'maxLength']; const customValidationOptions = [ { value: 'isPIVA', label: 'isPIVA' }, { value: 'isCodiceFiscale', label: 'isCodiceFiscale' }, @@ -132,7 +132,7 @@ const BuilderElementSettings = ({ closeSettings }) => { onChange={(e) => toggleRequired(e.value, k)}/> : null} - {textBasedValidatorFields.includes(k) || 'custom' === k + {numberBasedValidatorFields.includes(k) || 'pattern' === k || 'custom' === k ?
{ placeholder={__('Scegli', 'gepafin')}/>
: null} - {textBasedValidatorFields.includes(k) && !isNil(validators[k]) + {'pattern' === k && !isNil(validators[k]) ?
onChangeValidator(e.target.value, k)}/>
: null} + {numberBasedValidatorFields.includes(k) && !isNil(validators[k]) + ?
+ + onChangeValidator(e.target.value, k)}/> +
: null} ) : null} : null} From b6a4c92943c098b9b8d9b5fabb49e92b3d3f002d Mon Sep 17 00:00:00 2001 From: Vitalii Kiiko Date: Tue, 22 Oct 2024 17:52:23 +0200 Subject: [PATCH 2/2] - fix for fields with value 0; --- src/pages/BandoApplication/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pages/BandoApplication/index.js b/src/pages/BandoApplication/index.js index 5b3d9a5..aeecfd7 100644 --- a/src/pages/BandoApplication/index.js +++ b/src/pages/BandoApplication/index.js @@ -152,6 +152,7 @@ const BandoApplication = () => { trigger(); const formValues = getValues(); + console.log('formValues', formValues); const usedFieldsIds = pluck('id', formData); const newFormValues = Object.keys(formValues) .filter(v => usedFieldsIds.includes(v)) @@ -164,7 +165,7 @@ const BandoApplication = () => { fieldVal = tzAwareDate.toISOString().substring(0, 19); } - fieldVal = !fieldVal ? null : fieldVal; + fieldVal = isEmpty(fieldVal) ? null : fieldVal; if (formField && formField.name === 'fileupload') { fieldVal = is(Array, fieldVal) ? fieldVal.map(o => o.id).join(',') : null; }