- fixed styles for fileupload;

- fixed funcionality of form fields;
- added 'submit question' functionality;
This commit is contained in:
Vitalii Kiiko
2024-09-13 17:05:32 +02:00
parent a8471ba7aa
commit acd3a43d2e
11 changed files with 369 additions and 41 deletions

View File

@@ -11,6 +11,9 @@ import { storeSet, useStore } from '../../store';
// api
import FormsService from '../../service/forms-service';
// tools
import { isVAT } from '../../helpers/validators';
// components
import { Skeleton } from 'primereact/skeleton';
import { Button } from 'primereact/button';
@@ -30,11 +33,32 @@ const BandoApplication = () => {
control,
handleSubmit,
formState: { errors },
setValue,
trigger,
register,
getValues,
} = useForm({ defaultValues: {}, mode: 'onChange' });
const values = getValues();
const validationFns = {
isVAT
}
const onSubmit = (formData) => {
/*const newFormData = Object.keys(formData).reduce((acc, cur) => {
acc.push({
'fieldId': cur,
'fieldValue': formData[cur] && formData[cur].getMonth ? formData[cur].toISOString() : formData[cur]
});
return acc;
}, []);
console.log('newFormData', newFormData);
console.log('errors', errors);*/
};
const saveDraft = () => {
trigger();
const formData = getValues();
const newFormData = Object.keys(formData).reduce((acc, cur) => {
acc.push({
'fieldId': cur,
@@ -42,7 +66,8 @@ const BandoApplication = () => {
});
return acc;
}, []);
console.log('newFormData', newFormData)
console.log('newFormData', newFormData);
console.log('errors', errors);
};
const getBandoId = () => {
@@ -98,7 +123,31 @@ const BandoApplication = () => {
const placeholder = head(o.settings.filter(o => o.name === 'placeholder'));
const options = head(o.settings.filter(o => o.name === 'options'));
const step = head(o.settings.filter(o => o.name === 'step'));
const mime = head(o.settings.filter(o => o.name === 'mime').join(','));
const mime = head(o.settings.filter(o => o.name === 'mime'));
let mimeValue = '';
if (mime) {
mimeValue = mime.value.join(',');
}
const validations = Object.keys(o.validators).reduce((acc, cur) => {
if (o.validators[cur]) {
if (['min', 'max', 'minLength', 'maxLength', 'maxSize'].includes(cur)) {
acc[cur] = parseInt(o.validators[cur]);
} else if ('pattern' === cur) {
acc[cur] = new RegExp(o.validators[cur])
} else if ('isRequired' === cur) {
acc[cur] = o.validators[cur]
} else if ('custom' === cur && validationFns[o.validators[cur]]) {
if (!acc.validate) {
acc.validate = {}
}
acc.validate[cur] = validationFns[o.validators[cur]]
}
}
return acc;
}, {});
return <FormField
key={o.id}
@@ -107,12 +156,15 @@ const BandoApplication = () => {
label={label ? label.value : ''}
placeholder={placeholder ? placeholder.value : ''}
control={control}
register={register}
errors={errors}
defaultValue={values[o.id]}
maxFractionDigits={step}
accept={mime}
config={o.validators}
accept={mimeValue}
config={validations}
options={options ? options.value : []}
setDataFn={setValue}
sourceId={1}
/>
})}
@@ -125,6 +177,8 @@ const BandoApplication = () => {
<div className="appPageSection">
<div className="appPageSection__actions">
<Button
type="button"
onClick={saveDraft}
outlined
label={__('Salva bozza', 'gepafin')} icon="pi pi-save" iconPos="right"/>
<Button