Closed ryanvelbon closed 3 months ago
Could be useful if the Radio component had a property for allowing a null option which doesn't need to be explicitly passed into the :options property.
Radio
null
:options
This would be useful for creating filter options in an index page.
Instead of:
@php $subjectOptions = Subject::all(); $subjectOptions->prepend(['name' => 'All Subjects', 'id' => null]); @endphp <x-radio :options="$subjectOptions" wire:model.live="subjectId" />
We could do something like this:
@php $subjectOptions = Subject::all(); @endphp <x-radio :options="$subjectOptions" wire:model.live="subjectId" null-option="All Subjects" />
Here is another example but with an Enum instead:
namespace App\Enums; enum UserSex: string { case Male = 'm'; case Female = 'f'; }
Instead of
@php $sexOptions = UserSex::cases(); $sexOptions[] = ['name' => 'Any', 'value' => null]; @endphp <x-radio label="Gender" :options="$sexOptions" option-value="value" wire:model.live="sex" />
@php $sexOptions = UserSex::cases(); @endphp <x-radio label="Gender" :options="$sexOptions" option-value="value" wire:model.live="sex" null-option="Any" />
Unfortunately this approach does not work well. The "null" option does not keep selected when clicked. Am I missing something?
So it can be confusing for users.
Do you intend to rework it ?
Could be useful if the
Radio
component had a property for allowing anull
option which doesn't need to be explicitly passed into the:options
property.This would be useful for creating filter options in an index page.
Example 1
Instead of:
We could do something like this:
Example 2
Here is another example but with an Enum instead:
Instead of
We could do something like this: