multiple() select not work with afterStateUpdated

generate attribute values based on the selected attributes and add them into the repeater
25 Replies
LeandroFerreira
LeandroFerreira8mo ago
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...
Yacoub Al-haidari
Yacoub Al-haidariOP8mo ago
but if i remove the ->multiple() it access to the afterStateUpdated
LeandroFerreira
LeandroFerreira8mo ago
are you using a custom livewire component?
Yacoub Al-haidari
Yacoub Al-haidariOP8mo ago
no No just inside filament resource
LeandroFerreira
LeandroFerreira8mo ago
Are you considering using an array as the value for a multiple select, instead of a single string value? Any console errors?
Yacoub Al-haidari
Yacoub Al-haidariOP8mo ago
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
LeandroFerreira
LeandroFerreira8mo ago
I can not Access to the afterStateUpdated for getting the seleted values what is the output? null?
Yacoub Al-haidari
Yacoub Al-haidariOP8mo ago
No access , no touch the AttributeValues : i want to make this but with multiple() AttributeValues < i will provide you a new video Now
LeandroFerreira
LeandroFerreira8mo ago
no access.. what does it mean? 🤷‍♂️
Yacoub Al-haidari
Yacoub Al-haidariOP8mo ago
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
LeandroFerreira
LeandroFerreira8mo ago
remove ->reactive() use only ->live()
Yacoub Al-haidari
Yacoub Al-haidariOP8mo ago
Still not working
LeandroFerreira
LeandroFerreira8mo ago
doesn't it work?
Select::make('select')
->options([
'1' => 'Option 1',
'2' => 'Option 2',
])
->multiple()
->live()
->afterStateUpdated(function ($state) {
dd($state);
})
Select::make('select')
->options([
'1' => 'Option 1',
'2' => 'Option 2',
])
->multiple()
->live()
->afterStateUpdated(function ($state) {
dd($state);
})
Yacoub Al-haidari
Yacoub Al-haidariOP8mo ago
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); })
LeandroFerreira
LeandroFerreira8mo ago
live, not live onblur everytime you post a different code 🤷‍♂️ did you try my code? Did it work?
Yacoub Al-haidari
Yacoub Al-haidariOP8mo ago
this is the full code <<<
Yacoub Al-haidari
Yacoub Al-haidariOP8mo ago
It seems strange , works for single select but with multiple select not works I will try
LeandroFerreira
LeandroFerreira8mo ago
probably my code won't work if it is true..
Yacoub Al-haidari
Yacoub Al-haidariOP8mo ago
No it's not true , this works fine 🔥 , but my code not LOL 😅
Adnan Yalahow
Adnan Yalahow8mo ago
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
Yacoub Al-haidari
Yacoub Al-haidariOP8mo ago
3.2.80
Adnan Yalahow
Adnan Yalahow8mo ago
Try to clear the cache. I can't see any problem there
Want results from more Discord servers?
Add your server