feat: added ability to use groups in select's options()

Signed-off-by: Lukas Frey <mail@lukasfrey.cz>
This commit is contained in:
Lukas Frey
2023-07-24 12:50:38 +02:00
parent 5d10b326d5
commit bd07935e3c
4 changed files with 38 additions and 2 deletions
+1 -1
View File
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 }}"
+3 -1
View File
@@ -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();
}