How to validate repeater items certain conditions before create - Attributes IN repeater items
Hello.
Not possible with observer or with mutateFormDataBeforeCreate
I have a form to create dossiers, and each dossier can have multiple interveners; I am using a repeater. I need to validate, for example, if there are 3 interveners and not all 3 have the field invoiceable == true then halt and prevent the user from saving the Dossier and make Notification.
The fact is that if I use mutateFormDataBeforeCreate(array $data): array and I dd(data); I see no interveners array (no array for the repeater) and I cannot check.
Also, using an Observer, in the creating function, attributes DO NOT include repeaters, so this always gives an empty array for the interveners repeater (hasMany RelationShip):
Any ideas of how I can validate repeaters counts and fields attributes inside the repeaters???
Thanks.
3 Replies
Hello, you can use the filament validation and add your own custom validation rules please check: https://filamentphp.com/docs/3.x/forms/validation#custom-rules
Yes, tks, but I haven't found a validation rule that allows => equal to 1 or equal to another field's value, for example.
Or even validation where => this fieldA must be X if model.relationship.fieldB is less than model.relationship.fieldC
Maybe it is there in the Official docs, but I have not been able to find anything similar. Any help on this would be highly appreciated.
You can write your own validation rules from scratch, all the references on the link