livewire / flux

The official Livewire UI component library
https://fluxui.dev
476 stars 42 forks source link

Select {listbox|combobox} doesn't keep selected state from wire:model on page load #225

Closed codeduction closed 1 month ago

codeduction commented 1 month ago

With using Listbox or Combo if I have a model variable that sets an ID on reload this item doesn't get pre-selected and starts blank like nothing has been selected.

If you use no variant it work's as intended.

<?php

use Livewire\Volt\Component;

new class extends Component {
    public int $item_id = 4;
}
?>

<flux:card>
    <flux:field>
        <flux:label>Listbox doesn't auto select item ({{ $item_id }})</flux:label>

        <flux:select placeholder="Choose item..." variant="listbox" wire:model.live="item_id">
            <flux:option value="1">Laravel</flux:option>
            <flux:option value="2">Livewire</flux:option>
            <flux:option value="3">Alpine</flux:option>
            <flux:option value="4">Flux</flux:option>
        </flux:select>
    </flux:field>
</flux:card>
patrykszady commented 1 month ago

Similar to this i think. https://github.com/livewire/flux/issues/60 I have the same issue with:

<flux:select label="Vendor" wire:model.live="form.vendor_id" variant="combobox" placeholder="Choose vendor...">
            @foreach($vendors as $vendor)
                <flux:option>{{$vendor->name}}</flux:option>
            @endforeach
        </flux:select>
lucasromanojf commented 1 month ago

It looks like it only works with string values.

codeduction commented 1 month ago

It looks like it only works with string values.

Oh yeh, it does work when forcing it to string.

At least that is a work around for now.

calebporzio commented 1 month ago

Thank you for the report. This issue has been fixed and will be available in the next release.

patrykszady commented 1 month ago

Thank you for the report. This issue has been fixed and will be available in the next release.

Caleb! Thanks so much for working on these so diligently! Flux is already making my app look outstanding and making components I dreaded to code flawless… ohhh and my blade files … man they’re so clean !