F
Filament3w ago
Alan

Edit when dependent drop down shows all values.

On edit when i change the product name the values in drop down has all values irrespective of manufacture until i change manufacture.How to sort this if ($name === AllAttrib::ATTR_NAME_MANUFACTURER) { $component = Select::make("itemAttrib.$attribId.value") ->label(__($name)) ->options($taskAttrib['value'] ?? []) ->reactive() ->preload() ->live() ->afterStateUpdated(function (callable $get, callable $set) use ($attribId) { $manufacturerId = $get("itemAttrib.$attribId.value"); $set("itemAttrib.product.value", null); // Fetch product options based on selected manufacturer $productOptions = AttribValue::where('parent_id', $manufacturerId) ->orderBy('value') ->pluck('value', 'id') ->toArray(); $set('productOptions', $productOptions); }) ->default($value); } elseif ($name === AllAttrib::ATTR_NAME_PRODUCT_NAME) { $component = Select::make("itemAttrib.$attribId.value") ->label(__($name)) ->options(fn($get) => AttribValue::pluck('value', 'id')->toArray()) // Show all product options ->reactive() ->live() ->preload() ->default($value); } else { $component = Select::make("itemAttrib.$attribId.value") ->label(__($name)) ->options($taskAttrib['value'] ?? []) ->default($value); }
4 Replies
toeknee
toeknee3w ago
Not an error but a check issue, you are where empty or null values by the manufacture id being empty. condition the require to be:
$productOptions = $manufacturerId ? AttribValue::where('parent_id', $manufacturerId)
->orderBy('value')
->pluck('value', 'id')
->toArray()
: [];
$productOptions = $manufacturerId ? AttribValue::where('parent_id', $manufacturerId)
->orderBy('value')
->pluck('value', 'id')
->toArray()
: [];
Alan
Alan3w ago
implemented the above change but issue prevails , i want to load the options before state updated i think
toeknee
toeknee3w ago
Where do the options load?
Alan
Alan3w ago
i'm using livewire and in form function i want to load product options based on manufacture at the onload itself
Want results from more Discord servers?
Add your server