Susan
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
6 replies
How to override the submission of a form in a custom created page class.
I create a custom page class to reset the password.
“
class ResetPassword extends Page implements HasForms
{
use InteractsWithForms;
protected static ?string $navigationIcon = 'heroicon-o-document-text';
protected static string $view = 'filament.pages.reset-password';
protected static bool $shouldRegisterNavigation = false;
protected function getFormSchema(): array
{
return [
Card::make()->schema([
Forms\Components\TextInput::make('email')
->email()
->required()
->name('email')
->label('Current Email'),
Forms\Components\TextInput::make('password')
->password()
->required()
->minLength(6)
->name('password')
->label('Current Password'),
Forms\Components\TextInput::make('newpassword')
->password()
->required()
->minLength(6)
->name('newpassword')
->label('New Password'),
])
];
}
}“
And my custom view page is:
“
<x-filament::page>
<form>
@csrf
{{ $this->form }}
<div class="filament-page-actions flex flex-wrap ">
<button type="submit" class="text-white font-bold">
Submit
</button>
</div>
</form>
</x-filament::page> “
Now I need to customize the submission of this form in ResetPassword class. How can I do that.7 replies