multiple() select not work with afterStateUpdated
generate attribute values based on the selected attributes and add them into the repeater
25 Replies
Maybe you could reduce the code to highlight the issue as this topic title. The primary focus should be on a multi-select using the afterStateUpdated method and a simple repeater. I think including unnecessary methods can make the code more complex...
but if i remove the ->multiple() it access to the afterStateUpdated
are you using a custom livewire component?
no
No just inside filament resource
Are you considering using an array as the value for a multiple select, instead of a single string value?
Any console errors?
There is no error appear
This the video For what i am trying to make
https://www.loom.com/share/55c958ce385a49b78d9e3404fa998965?t=53&sid=fe5216de-b7bf-4d67-8cb3-5fd9071c860c
Yes I have the ->options(AttributeValue::where('attribute_id', $attributeId)->pluck('value', 'id')->toArray()) For getting the list of the AttributeValues
After i add the ->multiple() the select not works Because I can not Access to the afterStateUpdated for getting the seleted values
I can not Access to the afterStateUpdated for getting the seleted values
what is the output? null?
No access , no touch the AttributeValues :
i want to make this but with multiple() AttributeValues < i will provide you a new video Now
no access.. what does it mean? 🤷♂️
I mean , I can not access to the afterStateUpdated when the multiple is enable i added the dd() and select the AttributeValues select box but no dd() works in side the afterStateUpdated
remove ->reactive()
use only ->live()
Still not working
doesn't it work?
Not work <
Select::make("attributevalues{$attributeId}")
->label("اختر قيمة الخاصية: " . $attribute->name)
->options(AttributeValue::where('attribute_id', $attributeId)->pluck('value', 'id')->toArray())
->required()
->multiple()
->dehydrated()
->native(true)
->live(onBlur: true)
->afterStateUpdated(function (Set $set, Get $get, $state) use ($attributeId) {
dd($state);
$attributeValues = $get('attribute_values') ?? [];
$attributeValues[$attributeId] = [$state];
$set('attribute_values', $attributeValues);
$colors = $get('colors') ?? []; $variants = generateVariants($colors, $attributeValues);
$set('Has_variants', $variants); })
$set('attribute_values', $attributeValues);
$colors = $get('colors') ?? []; $variants = generateVariants($colors, $attributeValues);
$set('Has_variants', $variants); })
live, not live onblur
everytime you post a different code 🤷♂️
did you try my code? Did it work?
this is the full code <<<
It seems strange , works for single select but with multiple select not works
I will try
probably my code won't work if it is true..
No it's not true , this works fine 🔥 , but my code not LOL 😅
bro i have struggled this many times what version of filament are you using
when i updated the latest version of filament this solution will definitelywork
3.2.80
Try to clear the cache. I can't see any problem there