Passing data between Wizard steps

Hello, I am trying to achieve this: After a user inputs a url at first wizard step, and clicks next, to pass the url's data (it will call an API system, I will generate an array) at 5 Selects on second step, in order for a user to map the APIs data with our logic. I have tried to do this with "afterValidation()" function, with no luck
->afterValidation(
function ($state, callable $set) {
$xml_data = simplexml_load_file($state['url_input']);
// some logic here to return the array
$set('field_from_tab1', $resultArray);

})

,
->afterValidation(
function ($state, callable $set) {
$xml_data = simplexml_load_file($state['url_input']);
// some logic here to return the array
$set('field_from_tab1', $resultArray);

})

,
with no luck. Although, I tryied to do the same at Select->option() function, but it is not good practive to call the same API 5 times to get the same data... How it is possible to pass the data from one step to another? it is possible somehow to set a global variable, save the data globally and retrieve them later?
2 Replies
toeknee
toeknee13mo ago
That should work as far as I am ware, but you might need to set out of the wizard step with traversing i.w. $set('../field_from_tab1')
jelmerkeij
jelmerkeij12mo ago
Hi @JimKarvo I have tackled a similar problem like this today. In my case I'm using a wizard and in the first step you select a contact person. Depending on the client to which the contact person belongs you get a discount percentage when creating a quote. The quote lines are in a repeater and I need to prefill the discount percentage every time a quote line is added. I've introduced "global" variables within the main component to keep it from re-querying the database everytime. Not sure if this is a good practice but maybe this will point you in the right direction: https://gist.github.com/Jelmerkeij/1880137623bbfdcf5d605aa1b9244e67 (I put the code in my QuoteResource.php)
Gist
Filament 3 storing data in a 'global' variable
Filament 3 storing data in a 'global' variable. GitHub Gist: instantly share code, notes, and snippets.
Want results from more Discord servers?
Add your server