Newer
Older

Yassine Doghri
committed
<?php
declare(strict_types=1);
namespace App\Views\Components\Forms;

Yassine Doghri
committed
class Select extends FormComponent

Yassine Doghri
committed
{
/**
* @var array<string, string>
*/
protected array $options = [];
protected string $selected = '';
public function setOptions(string $value): void
{
$this->options = json_decode(html_entity_decode($value), true);
}

Yassine Doghri
committed
public function render(): string
{
$defaultAttributes = [

Yassine Doghri
committed
'class' => 'focus:border-contrast focus:ring-accent border-3 rounded-lg bg-elevated border-contrast ' . $this->class,
'data-class' => $this->class,

Yassine Doghri
committed
'data-select-text' => lang('Common.forms.multiSelect.selectText'),
'data-loading-text' => lang('Common.forms.multiSelect.loadingText'),
'data-no-results-text' => lang('Common.forms.multiSelect.noResultsText'),
'data-no-choices-text' => lang('Common.forms.multiSelect.noChoicesText'),
'data-max-item-text' => lang('Common.forms.multiSelect.maxItemText'),

Yassine Doghri
committed
];
$extra = array_merge($this->attributes, $defaultAttributes);

Yassine Doghri
committed
return form_dropdown($this->name, $this->options, old($this->name, $this->selected !== '' ? [$this->selected] : []), $extra);