comboBox.trigger(´chosen:update´)
what does this do in Jquery?
Anyone can give an example?
I dont see any effect or utility. I really search over 20 links over google and I cannot find the documentation.
CodePudding user response:
normally use
.trigger("chosen:updated");
$('.chosen').chosen("destroy").chosen();
trigger("chosen:updated");
And I think it's the Ultimate Solution: destroy it and rebuild it.
CodePudding user response:
comboBox.trigger(´chosen:update´)
comboBox
You will have a variable that points to a jquery collection containing a select
, likely setup using
let comboBox = $("#mySelect");
.trigger
Raises the named event
'chosen:update'
the name of the event to raise.
In this case, the event is namespaced, this just allows it to be specifically looked for in the chosen
namespace. It could also be .trigger("updated")
and chosen2 will likely pick it up - this stop other code such as .on("update"..
from triggering.
It also appears to be a typo as the event (depending on the version of chosen2) should be updated
.
All together, you call this code when you change the value of the underlying select
, eg:
var comboBox = $("#mySelect");
comboBox.val("newValue");
comboBox.trigger(´chosen:update´)
when your select
has been converted to a select2 combo box. Without which, the select2 UI would not be updated to match the new value.
NB: The event to trigger appears to change with each version of select2, it could be one of:
comboBox.trigger('chosen:updated');
comboBox.trigger('change');