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

selectablePlaceholder(false) doesn't work with required() for Filament\Forms\Components\Select #15203

Closed
lancepioch opened this issue Dec 30, 2024 · 1 comment
Labels

Comments

@lancepioch
Copy link

Package

filament/filament

Package Version

v3.2.131

Laravel Version

v11.5.0

Livewire Version

v3.5.18

PHP Version

8.3.8

Problem description

If selectablePlaceholder(false) is called and the select is NOT interacted with, then it passes null instead of the first option of the form.

IF you make that field ->required(), THEN it also says that field is necessary, even though the first value is already selected.

If you select a different dropdown value and then select the first one again, then it works as expected.

Expected behavior

null should NEVER be passed UNLESS the first default option's value is null WHEN ->selectablePlaceholder(false).

Steps to reproduce

Add a simple Select to any form:

Select::make('value')
    ->required()
    ->selectablePlaceholder(false)
    ->options([
        'test' => 'test',
        'abc' => 'abc',
        'def' => 'def',
    ]),

Go to http://application.test/admin/users/create and then click create without doing anything else.

The current behavior is that Filament incorrectly says the select dropdown is required. Which it is, but the first value is already selected. If you select a different value, then the first one again, it works as expected.

The expected behavior would be to get an Exception with a SQL error because I haven't included all the required fields for the default Laravel user. A full form that throws no exceptions doesn't change anything.

Reproduction repository (issue will be closed if this is not valid)

https://github.com/lancepioch/filament-bug

Relevant log output

No response

@danharrin
Copy link
Member

This is the behaviour of an HTML select if you do not have a blank option and do not have any options with the selected attribute. The first option is not really selected.

To fix this, you can pass ->default('test') so that an option has the selected attribute.

@danharrin danharrin closed this as not planned Won't fix, can't repro, duplicate, stale Jan 9, 2025
@github-project-automation github-project-automation bot moved this from Todo to Done in Roadmap Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

No branches or pull requests

2 participants