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

Not selecting option if value is integer 0 #52

Open
vesper8 opened this issue Mar 24, 2022 · 3 comments
Open

Not selecting option if value is integer 0 #52

vesper8 opened this issue Mar 24, 2022 · 3 comments

Comments

@vesper8
Copy link

vesper8 commented Mar 24, 2022

I have a tinyInteger field that I'm using the InlineSelect field on.

The value can be between 0 and 5

The field looks like this:


InlineSelect::make('Account Level')
                ->options(function () {
                    return [
                        0 => 'Normal User',
                        1 => 'Backer',
                        2 => 'Moderator',
                        3 => 'Tester',
                        4 => 'Admin',
                        5 => 'Super Admin',
                    ];
                })
                ->displayUsingLabels()
                ->inlineOnIndex()
                ->inlineOnLens()
                ->inlineOnDetail()
                ->disableTwoStepOnIndex()
                ->disableTwoStepOnLens()
                ->disableTwoStepOnDetail();

If the value is anything but 0, it correctly selects the currently selected option, but if the value is 0, it fails to select 'Normal User' and instead selects the Choose an option option

Any idea on how to remedy this?

Thanks!

@brandonferens
Copy link
Member

@vesper8 without any testing, I'm leaning toward the assuming key 0 is being interpolated as false not the integer 0. If you use the exact same options on a normal Select field, does it yield the same results?

@vesper8
Copy link
Author

vesper8 commented Mar 24, 2022

@brandonferens So.. I'm unsure exactly how the 'selected' value is picked but it appears to be through javascript?

Normally you'd have one of the option be selected such as in this html example:


<select id="account_level" class="flex-1 form-control form-select">
  <option value="" disabled="disabled">
    Choose an option
  </option>
  <option value="0" selected>
    Normal User
  </option>
  <option value="1">
    Backer
  </option>
  <option value="2">
    Moderator
  </option>
  <option value="3">
    Tester
  </option>
  <option value="4">
    Admin
  </option>
  <option value="5">
    Super Admin
  </option>
</select>

I noticed that with the InlineSelect, there is never any selected added to the options.

Certainly the above html does correctly select the option whose value is 0

@brandonferens
Copy link
Member

If you are able to find the fix, please feel free to issue a PR. If not, I will try and get to this next week.

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

2 participants