Not selecting option if value is integer 0
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 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 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
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.