nova-inline-select icon indicating copy to clipboard operation
nova-inline-select copied to clipboard

Not selecting option if value is integer 0

Open vesper8 opened this issue 3 years ago • 3 comments

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!

vesper8 avatar Mar 24 '22 00:03 vesper8

@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?

brandonferens avatar Mar 24 '22 13:03 brandonferens

@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

vesper8 avatar Mar 24 '22 14:03 vesper8

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.

brandonferens avatar Mar 24 '22 16:03 brandonferens