FilamentF
Filament2y ago
Vp

Access form data inside beforeFormValidated()

I have country code field, I want to save +012 (notice plus sign) in database. but on input, I don't want user to insert "+" so I use mutateFormDataUsing() to append before save, but however this doesn't work with ->unique() validation, it always try to save to DB.

My codes:
Forms\Components\TextInput::make('country_code')
    ->prefix('+')
    ->unique(ignoreRecord: true),

Actions\CreateAction::make()
    ->beforeFormValidated(function () {
        // how to access form data here
    })

EDIT
I notice that mutateFormDataUsing() run after validation, so how can I access form data inside ->beforeFormValidated()?
Was this page helpful?