Combo: Allow entry not in list


#1

In past versions of DHX, the combo box had the ability to accept entries that were not in its data list. In DHX 6+, it seems like the input box is nothing more than a filter for the data list, and does not retain the data typed into it. I want to present my users with a list of options, but allow them to type in their own value if it’s not one of those options. Is there a way to enable this?


#2

You may “auto create” a new option for the entered text that is not in the combo optionsa list.
Just try to use something like:

combobox.events.on("Input", function(value) {
   inp_val=value;
});
combobox.events.on("BeforeClose", function () {
   if (!combobox.getValue()) {
      const uId = "u" + Math.floor(Math.random() * 10000)
      combobox.data.add({ "value": inp_val, "id": uId })
      dhx.awaitRedraw().then(function () {
         form.getItem("combo").setValue(uId)
      })
   }
});