Make the field required only on creation.
I have user form with field password. I need to make the form mandatory only if it is in creation state. On updation, the field should be non-mandatory.
TextInput::make('password')
->password()
->dehydrateStateUsing(fn ($state) => Hash::make($state))
->dehydrated(fn ($state) => filled($state))
->required(fn (Page $livewire) => ($livewire instanceof CreateUser) ? false : true),
This is what I h ave given, please advice me how to make it working.
Thanks
Solution:Jump to solution
->required(fn (string $context) => $context === 'create')
This is working for me. Thank you....
4 Replies
You switch between false and true. Your code says make it always required but in CreateUser. Make it simple
->required(fn (Page $livewire) => $livewire instanceof CreateUser)
.
Another way, use this ->required(fn (string $context) => $context === 'create')
Solution
->required(fn (string $context) => $context === 'create')
This is working for me. Thank you.
You're welcome. Don't forget to mark it as a solution.
Yeah sure.