Hi there,
How can I clear all of the selected options in a multiselect with one click? Is there a way to make it "reset" the entire box if I want to?
Thanks!
Hi
Try this
<form script="reset.js">
<label>resetbutton</label>
<fieldset submitButton="false">
<input type="multiselect" token="field1">
<label>field1</label>
<choice value="one">One</choice>
<choice value="two">Two</choice>
<choice value="three">Three</choice>
</input>
<html>
<input type="button" id="reset" value="Reset"/>
</html>
</fieldset>
</form>
Javascript:
require([
'jquery',
'splunkjs/mvc',
'splunkjs/mvc/simplexml/ready!'
], function($, mvc) {
var tokens = mvc.Components.get("default");
$("#reset").click(function(){
tokens.unset("form.field1");
});
});
Hi
Try this
<form script="reset.js">
<label>resetbutton</label>
<fieldset submitButton="false">
<input type="multiselect" token="field1">
<label>field1</label>
<choice value="one">One</choice>
<choice value="two">Two</choice>
<choice value="three">Three</choice>
</input>
<html>
<input type="button" id="reset" value="Reset"/>
</html>
</fieldset>
</form>
Javascript:
require([
'jquery',
'splunkjs/mvc',
'splunkjs/mvc/simplexml/ready!'
], function($, mvc) {
var tokens = mvc.Components.get("default");
$("#reset").click(function(){
tokens.unset("form.field1");
});
});
Thanks that works too!
@mwdbhyat
You have to just unset that input.
Like, if XML
<unset token="multiselect_token"></unset>
Using Javascript:
var defaultTokenModelun = mvc.Components.getInstance('default', {create: true});
var submittedTokenModelun = mvc.Components.getInstance('submitted', {create: true});
function unsetToken(name) {
defaultTokenModelun.unset(name);
submittedTokenModelun.unset(name);
}
$(document).on("click", "#ButtonId", function() {
unsetToken("multiselect_token")
});
Thanks both worked!