wireui / wireui

TallStack UI components
https://v1.wireui.dev
MIT License
1.37k stars 166 forks source link

Select (x-select) looses all options after being disabled and again enabled afterwards #652

Open tariktokic opened 1 year ago

tariktokic commented 1 year ago

Describe the bug When using the <x-select> component and disabling and enabling it later again, all options from the :options are gone.

To Reproduce Steps to reproduce the behavior:

  1. Create the component like this:

                        <x-select
                            :options="$listOfYears"
                            wire:model.lazy="year"
                            required
                            label="Year"
                            :disabled=$yearIsDisabled
                        />

    where the list of years is $this->listOfYears = [(int)date('Y')-1, (int)date('Y'), (int)date('Y')+1]; and $this->yearIsDisabled=false.

  2. Set $this->yearIsDisabled=true.

  3. Set $this->yearIsDisabled=false.

Expected behavior After enabling the component I can select new options. Unfortunately they are all gone.

Dependencies

Desktop (If applicable, please complete the following information):

spardobo commented 7 months ago

I'm having the same issue, is there any workaround for this?

rivalex commented 7 months ago

Same problem here ... maybe a refresh() or redraw() method will be useful. thanks in advance.

misenhei commented 3 months ago

To force the options to be rebuilt after disabling you can randomize wire:key to have Livewire rebuild:

<div wire:key="{{ 'x-select-year-' . rand() }}"
   <x-select
         :options="$listOfYears"
         wire:model.lazy="year"
         required
         label="Year"
         :disabled=$yearIsDisabled
    />
</div>