Unable to hide similar select option element

It’s for resetting the selection when the selection becomes bad.

So for example, if you change the value of the first select to C; the page has not been psychicly pre-deterministic to know you were going to pick C for the first box. The value of the second box could already be C.

If it is, you’re in a bad state - the selected option in the second box is now invalid. What needs to happen?

Well, we could tell the second box to pick a different value. But we dont really want to say that “C was invalid, you pick D instead” (maybe you do, but thats not the default behavior I would go for personally - what happens if they choose the last value in the box?) so instead we tell the box to set its value to the value of our non-selection (which in this case is -1), and then register to select2 (and any other javascript listening for changes to the select box) that a change has happened, and it needs to update itself.

$("#destinationLocations").val(-1).trigger("change");
1 Like