This repository has been archived by the owner on Feb 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
68fca2e
commit 01ec412
Showing
3 changed files
with
52 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require([ | ||
'jquery', | ||
'underscore', | ||
'splunkjs/mvc', | ||
'splunkjs/mvc/simplexml/ready!' | ||
], function( | ||
$, | ||
_, | ||
mvc | ||
) { | ||
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) { | ||
this.val([first_choice_value]); | ||
} | ||
// 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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters