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
Unknown Userβ€’2y ago
Message Not Public
Sign In & Join Server To View
cpereiraweb
cpereirawebOPβ€’2y ago
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!
wyChoong
wyChoongβ€’2y ago
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) => ... )
cpereiraweb
cpereirawebOPβ€’2y ago
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 πŸ˜ƒ
wyChoong
wyChoongβ€’2y ago
how are you blocking the the DOB field? validation shouldn't validate for disabled field thou
cpereiraweb
cpereirawebOPβ€’2y ago
I intended to use TextInput::make('birth_date')->disabled() on edit screen.
wyChoong
wyChoongβ€’2y ago
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?
cpereiraweb
cpereirawebOPβ€’2y ago
I'm using in Resource class. I'll try this πŸ˜ƒ
Want results from more Discord servers?
Add your server