Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.0.23] flux:select: option with zero value sets the option label as value and not zero #667

Closed
lucasromanojf opened this issue Nov 13, 2024 · 2 comments

Comments

@lucasromanojf
Copy link

Hello,

When using a flux:select which has an option of value zero, if I select this option, the binded model is set with the option label and not with zero. It was working fine on previous versions.

You can see in the following example that, when selecting the first option, $value variable is set to "Option 0" and not to "0" (zero).

<?php

use function Livewire\Volt\{state};

state([
    'value' => '',
    'options' => [
        ['label' => 'Option 0', 'value' => '0'],
        ['label' => 'Option 1', 'value' => '1'],
        ['label' => 'Option 2', 'value' => '2'],
    ]
]);

?>

<div>
    <flux:select
        wire:model.live="value"
        placeholder="Select an option"
    >
        @foreach ($options as $option)
            <flux:option
                :key="$option['value']"
                :value="$option['value']"
            >
                {{ $option['label'] }}
            </flux:option>
        @endforeach
    </flux:select>

    Selected option: {{ $value }}
</div>
@ThomasEnssner
Copy link
Contributor

Same issue here.

As long as you are using <flux:select ...> without a variant. You can use regular <option value="0">myLabel</option> as workaround.

@calebporzio
Copy link
Contributor

Thanks for this, there was a loose equality check on the $value prop in the option component instead of checking for a strict null.

Will be fixed in the next release. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants