Custom Field with Wizard

Hi, I would like to build a custom field that checks the inserted data from other fields against an API. How can I build this, so the user can't go to the next step until my API returns something positive? Thank you!
10 Replies
LeandroFerreira
what about Step::()->afterValidation() ?
Florian Langer
Florian LangerOP2y ago
uh it's not documented is it? How am I supposed to use it, because I don't understand how I can return true from my custom component and use that afterValidateion callback. I'm sorry for being confused.
LeandroFerreira
Can you explain more about the custom field?
Florian Langer
Florian LangerOP2y ago
actually I am not sure if I even need it. I just want to run a method from my API service and it either returns true or false. While it's being checked or returns false the user can't go further in the wizard.
LeandroFerreira
where/when would you like to trigger the method/api? could it be a prefix/suffixAction?
Florian Langer
Florian LangerOP2y ago
If the user goes to step 2 (so, after he/she inserted the necessary data)
LeandroFerreira
You can use Step1->afterValidation I think
Florian Langer
Florian LangerOP2y ago
but I think that's just a hook to do something after validation but you can't really disable the next step button etc.
LeandroFerreira
let me elaborate an example Something like this:
Step::make('Step1')
->schema([
TextInput::make('myValue')
])
->afterValidation(function ($get) {

//$get('myValue'), $get('myValue2')... if you want to get the value from the form

//api request..
$request = false; //'https://myapi.com...';

throw_if(!$request, ValidationException::withMessages([
'data.myValue' => ['The field is invalid.'],
]));

//you can also use a Filament notification..
}),
Step::make('Step1')
->schema([
TextInput::make('myValue')
])
->afterValidation(function ($get) {

//$get('myValue'), $get('myValue2')... if you want to get the value from the form

//api request..
$request = false; //'https://myapi.com...';

throw_if(!$request, ValidationException::withMessages([
'data.myValue' => ['The field is invalid.'],
]));

//you can also use a Filament notification..
}),
Prodex
Prodex2y ago
Nice will try it out later thanks 🙏

Did you find this page helpful?