Can I inject a variable amount of dropdowns based on reactive field value?
Hello, the use case is rather simple. I have a dropdown with some products. After selecting one I want to display a number of other dropdowns based on that selection. Might be 1 dropdown, might be 4. I don't know until the selection is made. Is that possible with form builder?
11 Replies
probably, but how are the values gonna be stored from those dropdowns?
The lifecycle hooks, on store or update i parse the fields
i dont get it
json?
i'll try to explain better, here's a video of how I have it now, first drop down where i choose the product has reactive() on it and the second dropdown loads some options based on that particular product
https://share.cleanshot.com/JMp9pcS0
You see that for attribute it has something like Tricou dama, alb, M
I want that single select to be 3 different selects in this case
some other product might require 2 selects instead of 3
i want to know if there's a way to programatically inject form components in the schema based on the selected product from the first dropdown
make sure the original field is reactive()
i will try this right now, thank you so much
you might need to add an afterStateUpdated() to the original field to $set() each select to
null
but see if that works firstyeah, those are small workarounds i can figure out, this was the main issue I didn't know how to tackle, thank you again
Sorry to bother you again but I'm getting a weird error after creating the product. It didn't use to happen before doing what you suggested. It creates the product without issue but "addEagerConstraints() on null" error pops up and the stack trace isn't really helping. Do i need to somehow destroy those selects after the creation process is finalized?
CleanShot 2023-06-29 at 16.22.28
Video uploaded to CleanShot Cloud
if anyone runs into this, i fixed the error by refreshing the parent model like this
->after(function (Tables\Contracts\HasRelationshipTable $livewire) {
$livewire->getRelationship()->getParent()->refresh();
}),
}),