brianvoe / slim-select

Slim advanced select dropdown
http://slimselectjs.com
MIT License
1.03k stars 195 forks source link

in livewire dependent simple-selects not updating #539

Closed hardevine closed 5 months ago

hardevine commented 5 months ago

class CentreForm extends Component
{

    public $centre = [
            'country' => '',
    ];

    #[Computed]
    public function countryList()
    {
        $c = collect(countryList())->mapWithKeys(fn($item, $key) => [$item => $item]);

        return $c->toArray();
    }

   #[Computed]
      public function statesList()
      {
          $cc = countryCode($this->centre['country']);
          $c = stateList($cc);
          return $c;
      }

    public function updatedCentreCountry()
    {
        $this->centre['state'] = '';
    }
<div
    x-data="{
        value: @entangle($attributes->wire('model')).live,
    }"
    x-init="new SlimSelect({
        select: $refs.simple_select,
        settings: {searchHighlight: true}
      }).setSelected(value,false)"
    x-on:afterChange="value = $event.target.value"
    {{ $attributes->whereDoesntStartWith('wire:model') }}
    wire:ignore
>
    <select x-model="value" x-ref="simple_select" {{ $attributes->whereDoesntStartWith('wire:model')->merge(['class' => '']) }}>
        <option value="">-</option>
        {{ $slot }}
        @foreach($options as $key => $value)
            <option value="{{ $key }}">{{ $value }}</option>
        @endforeach
    </select>
</div>
brianvoe commented 5 months ago

Sorry i cannot control what livewire does to slim select. I dont even know if its compatable.