fix: update form fields to allow nullable values for locatore, email, and numero

This commit is contained in:
Marco Pedone 2025-08-26 17:38:12 +02:00
parent fc02a6debc
commit ec818eb7ff

View file

@ -73,9 +73,9 @@ const AnnuncioEditForm = ({ data }: { data: Annunci }) => {
titolo_en: z.string().nonempty("Inserisci un titolo valido"),
desc_en: z.string().nonempty("Inserisci una descrizione valida"),
status: z.string().nonempty("Seleziona uno stato"),
locatore: z.string().nonempty("Inserisci il locatore"),
email: z.email(),
numero: z.string().nonempty("Inserisci un numero di telefono"),
locatore: z.string().nullable(),
email: z.email().nullable(),
numero: z.string().nullable(),
});
type EditAnnuncioFormValues = z.infer<typeof EdiAnnuncioSchema>;
@ -98,9 +98,9 @@ const AnnuncioEditForm = ({ data }: { data: Annunci }) => {
titolo_en: data.titolo_en || "",
desc_en: data.desc_en || "",
status: data.stato || "",
locatore: data.locatore || "",
email: data.email || "",
numero: data.numero || "",
locatore: data.locatore || null,
email: data.email || null,
numero: data.numero || null,
};
z.config(z.locales[locale]());
@ -356,7 +356,15 @@ const AnnuncioEditForm = ({ data }: { data: Annunci }) => {
</div>
<FormControl>
<Input placeholder="" {...field} id="locatore" />
<Input
placeholder=""
{...field}
id="locatore"
value={field.value || undefined}
onChange={(e) =>
field.onChange(e.target.value || null)
}
/>
</FormControl>
</FormItem>
)}
@ -378,6 +386,10 @@ const AnnuncioEditForm = ({ data }: { data: Annunci }) => {
placeholder="esempio@email.com"
{...field}
id="email"
value={field.value || undefined}
onChange={(e) =>
field.onChange(e.target.value || null)
}
/>
</FormControl>
</FormItem>
@ -396,7 +408,12 @@ const AnnuncioEditForm = ({ data }: { data: Annunci }) => {
</div>
<FormControl>
<PhoneInput {...field} id="numero" />
<PhoneInput
{...field}
id="numero"
value={field.value || undefined}
onChange={(n) => field.onChange(n || null)}
/>
</FormControl>
</FormItem>
)}