Add the ability to use a select list for template attributes

This commit is contained in:
Deon George 2025-06-22 22:08:38 +10:00
parent 3ad4c446ea
commit 3bf97fc0d1
4 changed files with 53 additions and 2 deletions

View File

@ -69,6 +69,19 @@ class Template
return collect($this->attributes->get($key)); return collect($this->attributes->get($key));
} }
/**
* Return an template attributes select options
*
* @param string $attribute
* @return Collection|NULL
*/
public function attributeOptions(string $attribute): Collection|NULL
{
return ($x=$this->attribute($attribute)?->get('options'))
? collect($x)->map(fn($item,$key)=>['id'=>$key,'value'=>$item])
: NULL;
}
/** /**
* If the attribute has been marked as read-only * If the attribute has been marked as read-only
* *

11
public/css/custom.css vendored
View File

@ -14,11 +14,20 @@ attribute#objectclass .input-group-end:not(input.form-control) {
z-index: 5; z-index: 5;
} }
.input-group:first-child .select2-container--bootstrap-5 .select2-selection { /* select forms that have nothing next to them */
.select-group:first-child .select2-container--bootstrap-5 .select2-selection {
border-radius: 4px !important;
}
.input-group:first-child:not(.select-group) .select2-container--bootstrap-5 .select2-selection {
border-bottom-right-radius: unset; border-bottom-right-radius: unset;
border-top-right-radius: unset; border-top-right-radius: unset;
} }
.select2-container .select2-selection--single .select2-selection__rendered {
font-size: 0.88em;
}
input.form-control.input-group-end { input.form-control.input-group-end {
border-bottom-right-radius: 4px !important; border-bottom-right-radius: 4px !important;
border-top-right-radius: 4px !important; border-top-right-radius: 4px !important;

View File

@ -63,7 +63,8 @@
</div> </div>
@switch($template?->attributeType($o->name)) @switch($template?->attributeType($o->name))
@case('type') @case('select')
<x-attribute.template.select :o="$o" :template="$template" :edit="(! $template?->attributeReadOnly($o->name)) && $edit" :new="$new"/>
@break; @break;
@default @default

View File

@ -0,0 +1,28 @@
<!-- $o=Attribute::class -->
<x-attribute.layout :edit="$edit" :new="$new" :o="$o">
@foreach($o->langtags as $langtag)
@foreach(($o->tagValues($langtag)->count() ? $o->tagValues($langtag) : [$langtag => NULL]) as $key => $value)
@if($edit)
<div class="select-group">
<x-form.select
@class(['is-invalid'=>($e=$errors->get($o->name_lc.'.'.$langtag.'.'.$loop->index)),'mb-1','border-focus'=>! $o->tagValuesOld($langtag)->contains($value)])
id="{{ $o->name_lc }}_{{$loop->index}}{{$template?->name ?: ''}}"
name="{{ $o->name_lc }}[{{ $langtag }}][]"
:value="$value"
:options="$template->attributeOptions($o->name_lc)"
allowclear="true"
:disabled="! $new"
:readonly="FALSE"/>
<div class="invalid-feedback pb-2">
@if($e=$errors->get($o->name_lc.'.'.$langtag.'.'.$loop->index))
{{ join('|',$e) }}
@endif
</div>
</div>
@else
{{ $o->render_item_old($langtag.'.'.$key) }}
@endif
@endforeach
@endforeach
</x-attribute.layout>