- added registartion page;
- implemented validation helper-functions; - fixed form fields datepicker and datepicker range; - updated routes logic; - fixed FAQ items editing/submission;
This commit is contained in:
@@ -17,6 +17,18 @@ import { Button } from 'primereact/button';
|
||||
import FormField from '../../components/FormField';
|
||||
import set404FromErrorResponse from '../../helpers/set404FromErrorResponse';
|
||||
|
||||
// tools
|
||||
import {
|
||||
isCAP,
|
||||
isCodiceFiscale,
|
||||
isEmail,
|
||||
isEmailPEC,
|
||||
isIBAN,
|
||||
isMarcaDaBollo,
|
||||
isPIVA,
|
||||
isUrl
|
||||
} from '../../helpers/validators';
|
||||
|
||||
const BandoFormsPreview = () => {
|
||||
const { id, formId } = useParams();
|
||||
const navigate = useNavigate();
|
||||
@@ -28,8 +40,20 @@ const BandoFormsPreview = () => {
|
||||
handleSubmit,
|
||||
formState: { errors },
|
||||
getValues,
|
||||
register,
|
||||
setValue
|
||||
} = useForm({ defaultValues: {}, mode: 'onChange' });
|
||||
const values = getValues();
|
||||
const validationFns = {
|
||||
isPIVA,
|
||||
isCodiceFiscale,
|
||||
isCAP,
|
||||
isIBAN,
|
||||
isEmail,
|
||||
isEmailPEC,
|
||||
isUrl,
|
||||
isMarcaDaBollo
|
||||
}
|
||||
|
||||
const onSubmit = () => {}
|
||||
|
||||
@@ -38,7 +62,7 @@ const BandoFormsPreview = () => {
|
||||
const bandoId = !isNaN(parsedId) ? parsedId : 0;
|
||||
const parsedFormId = parseInt(formId)
|
||||
const bandoFormId = !isNaN(parsedFormId) ? parsedFormId : 0;
|
||||
navigate(`/tenders/${bandoId}/forms/${bandoFormId}`);
|
||||
navigate(`/bandi/${bandoId}/forms/${bandoFormId}`);
|
||||
}
|
||||
|
||||
const getFormCallback = (data) => {
|
||||
@@ -94,17 +118,49 @@ const BandoFormsPreview = () => {
|
||||
const label = head(o.settings.filter(o => o.name === 'label'));
|
||||
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'));
|
||||
let mimeValue = '';
|
||||
|
||||
if (mime) {
|
||||
mimeValue = mime.value.map(o => o.code).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}
|
||||
type={o.name}
|
||||
fieldName={`field_${o.id}`}
|
||||
fieldName={o.id}
|
||||
label={label ? label.value : ''}
|
||||
placeholder={placeholder ? placeholder.value : ''}
|
||||
control={control}
|
||||
register={register}
|
||||
errors={errors}
|
||||
defaultValue={values[`field_${o.id}`]}
|
||||
config={o.validators}
|
||||
defaultValue={values[o.id]}
|
||||
maxFractionDigits={step}
|
||||
accept={mimeValue}
|
||||
config={validations}
|
||||
options={options ? options.value : []}
|
||||
setDataFn={setValue}
|
||||
sourceId={0}
|
||||
/>
|
||||
})}
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user