mirror of
https://github.com/filamentphp/filament.git
synced 2026-10-24 12:04:06 +08:00
feat: added ability to use groups in select's options()
Signed-off-by: Lukas Frey <mail@lukasfrey.cz>
This commit is contained in:
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -168,3 +168,7 @@ select:not(.choices) {
|
||||
.choices__input::-ms-reveal {
|
||||
@apply hidden h-0 w-0;
|
||||
}
|
||||
|
||||
.choices__group {
|
||||
@apply p-2 text-gray-400 dark:text-gray-500 pt-6 first:pt-2;
|
||||
}
|
||||
|
||||
@@ -54,6 +54,36 @@
|
||||
</option>
|
||||
@endif
|
||||
|
||||
@foreach ($getOptions() as $value => $label)
|
||||
@if (is_array($label))
|
||||
<optgroup label="{{ $value }}">
|
||||
@foreach($option as $v => $l)
|
||||
<option
|
||||
value="{{ $v }}"
|
||||
@disabled($isOptionDisabled($v, $l))
|
||||
>
|
||||
@if ($isHtmlAllowed)
|
||||
{!! $l !!}
|
||||
@else
|
||||
{{ $l }}
|
||||
@endif
|
||||
</option>
|
||||
@endforeach
|
||||
</optgroup>
|
||||
@else
|
||||
<option
|
||||
value="{{ $value }}"
|
||||
@disabled($isOptionDisabled($value, $label))
|
||||
>
|
||||
@if ($isHtmlAllowed)
|
||||
{!! $label !!}
|
||||
@else
|
||||
{{ $label }}
|
||||
@endif
|
||||
</option>
|
||||
@endif
|
||||
@endforeach
|
||||
|
||||
@foreach ($getOptions() as $value => $label)
|
||||
<option
|
||||
value="{{ $value }}"
|
||||
|
||||
@@ -609,7 +609,9 @@ class Select extends Field implements Contracts\HasAffixActions, Contracts\HasNe
|
||||
protected function transformOptionsForJs(array $options): array
|
||||
{
|
||||
return collect($options)
|
||||
->map(fn ($label, $value): array => ['label' => $label, 'value' => strval($value)])
|
||||
->map(fn ($label, $value): array => is_array($label)
|
||||
? ['label' => $value, 'choices' => $this->transformOptionsForJs($label)]
|
||||
: ['label' => $label, 'value' => strval($value)])
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user