Hi,
I'm using the select2 input on my dashboard and it all works fine, unless I try to declare a default value.
Initially I tried this:
protected function onInit()
{
$this->cssClass("form-control")
->multiple(true)
->placeHolder("Please select")
->value([2]);
}
This works fine and it actually set item with the ID=2 as the selected default. However when I then later change the selection and try to get the value from the select on my other dashboard widgets I still only get the default value, even if I had changed it.
$sites = $this->sibling("mySiteSelect")->value();
Result is still = [2], even if I changed the values.
I then reviewed the documentation and found the defaultOption() method. So I tried this:
protected function onInit()
{
$this->cssClass("form-control")
->multiple(true)
->placeHolder("Please select")
->defaultOption([2]);
}
Unfortunately, this doesn't select the item with the id=2, although it should according to the documentation. It just adds a new item with the label 2 to the list and doesn't even select it.
I marked this as a bug, as it doesn't do what it says in the documentation.
Can you please either correct it or let me know what I'm doing wrong?
Thanks
Christian