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
LeandroFerreiraβ€’17mo ago
what about Step::()->afterValidation() ?
Florian Langer
Florian LangerOPβ€’17mo 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
LeandroFerreiraβ€’17mo ago
Can you explain more about the custom field?
Florian Langer
Florian LangerOPβ€’17mo 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
LeandroFerreiraβ€’17mo ago
where/when would you like to trigger the method/api? could it be a prefix/suffixAction?
Florian Langer
Florian LangerOPβ€’17mo ago
If the user goes to step 2 (so, after he/she inserted the necessary data)
LeandroFerreira
LeandroFerreiraβ€’17mo ago
You can use Step1->afterValidation I think
Florian Langer
Florian LangerOPβ€’17mo 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
LeandroFerreiraβ€’17mo ago
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
Prodexβ€’17mo ago
Nice will try it out later thanks πŸ™
Want results from more Discord servers?
Add your server