Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
multiselect force default select input
// TESTED in 7.3.x and 6.5.x (so should work in all other versions)
], function(
) {
var multiselects = _(mvc.Components.toJSON()).filter(function(obj) {
// This seems hacky; there should be a better way to do this
return obj.settings && obj.settings.get("type") === "multiselect" && obj.$el[0].className.indexOf("input-multiselect") > -1;
_(multiselects).each(function(multiselect) {
multiselect.on("change", function() {
var values = this.val();
// I assume the default multiselect value will be the first (hardcoded) choice
// Like <choice value="*">All</choice>
// If there is no hardcoded choice, then .options.choices[0] won't exist...
var first_choice_value = this.options.choices[0].value;
// If the user removed everything then add the first choice "All" back
if(values.length === 0) {
// If the user choose something else then remove the first choice "All" (if it's there)
else if(values.indexOf(first_choice_value) >= 0 && values.length > 1) {
this.val(_.without(values, first_choice_value));

This comment has been minimized.

Copy link

@PellionP PellionP commented Nov 13, 2016

Hi there,

Great JS, used it often in 6.3 & 6.4, so big thanks !

Apparently, there is a change in 6.5 that prevent it to work :/

They are talking about it there :

Trying to debug, without luck for now :/


This comment has been minimized.

Copy link
Owner Author

@hobbes3 hobbes3 commented Jun 1, 2017

@PellionP It works for 6.5 now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment