Validation rule active only when creating a record
Guys, I researched a lot about this but I didn't find references, so I ask you for help: and a form, I need a validation rule to be applied only when I'm creating a new record. If I am editing this rule should not be considered. Can anyone point me in the correct direction? Thank you all in advance!
8 Replies
Unknown Userβ’2y ago
Message Not Public
Sign In & Join Server To View
Actually I expected to have the possibility to use a callback function to achieve this but I didn't find how. I will try this approach. Thanks for sharing!
while this doesn't make much sense to only validate while creating
you should be able to get to use one of this in closure
->validate(fn ($context, $livewire) => ... )
Let me explain the scenario: when enrolling a student, I need to verify that the student is between 11 and 47 months old. This check is only required when creating the record. On the editing screen, the date of birth field will be blocked.
I'll try this. Thanks π
how are you blocking the the DOB field? validation shouldn't validate for disabled field thou
I intended to use TextInput::make('birth_date')->disabled() on edit screen.
are you defining the form schema separately in create and edit page? or in resource class?
if in resource class,
->rules([..your validation here...])->disabled(fn($context) => $context == 'edit')
does not work for you?I'm using in Resource class. I'll try this π