Improve form validation and guide users to fill out all the required fields

Updates form validation logic to allow zero quantity and adds quantity placeholder.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 91318273-c764-4fd4-be04-bdc12c38af32
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/0715008c-7244-40f4-befc-26c014852236/36c2c7b9-873e-432e-9d49-6ced2f07df49.jpg
This commit is contained in:
michaelschal committed 2025-07-09 18:28:20 +00:00
1 parent 2377483fd7
commit 42b249e5b0
2 files changed
+10 -2

No files matched your search

+1 -1
View File
@@ -281,7 +281,7 @@ export default function NewSaleForm({ onSaveSale }: NewSaleFormProps) {
<FormItem>
<FormLabel>Quantité <span className="text-destructive">*</span></FormLabel>
<FormControl>
<Input type="number" min="1" placeholder="1" {...field} />
<Input type="number" min="1" placeholder="Entrez la quantité" {...field} />
</FormControl>
<FormMessage />
</FormItem>
+9 -1
View File
@@ -30,7 +30,15 @@ export function validateRequiredFields(formData: any): string[] {
];
return requiredFields
.filter(field => !formData[field.key] || formData[field.key].toString().trim() === '')
.filter(field => {
const value = formData[field.key];
// Pour la quantité, accepter 0 comme valeur valide
if (field.key === 'quantite') {
return value === '' || value === null || value === undefined;
}
// Pour les autres champs, vérifier si vide ou juste des espaces
return !value || value.toString().trim() === '';
})
.map(field => field.label);
}