Add empty item in select
kamov opened this issue · 4 comments
kamov commented
I am using ViewModels for populate a select input.
I would like to add an empty options like "Select item" as first options.
How to archive this?
Thanks
sebastiandedeyne commented
Could you share your current ViewModel and Blade component?
kamov commented
It's same to example on docs.
kamov commented
Ok, I think that I get a solution now...
by adding directly in the component...
sebastiandedeyne commented
Directly in the component sounds like a good solution 👍
Alternatively, you could add the item to the options
property in __construct
.
public function __construct(string $name, $options = null, $selected = null)
{
$this->name = $name;
$this->options = array_merge([0 => 'Select item...'], $options);
$this->selected = old($name, $selected);
}