KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Reset button for Select2 fields #87

Open bysystem opened this topic on on Aug 22, 2017 - 7 comments

bysystem commented on Aug 22, 2017

Dear support team,

I have created several MultiSelect fields by using Select2 package. There is a submit button which fires the MultiSelected options.

If the user has made a lot of selections, it's very hard for the to deselect the optioned one by one! Is there any possibility to create a Reset button which deselect all the options by one click?

I tried it with input type reset but no success!!

KoolReport commented on Aug 22, 2017

You can create a Clear button and run following script:

$('#name_of_select2').val(null).trigger("change");

This will clear all the selections

bysystem commented on Aug 22, 2017

Ok, thx a lot!I'll try this immediately.

But: How can I assign the clear button script to more than 1 select2 field?

Because I would like to create only 1 clear button for ALL the select2 fields together instead of 1 clear buttons for EACH field!

KoolReport commented on Aug 22, 2017

It is simple, when click to the Clear buttons, you call above script for two select2s, changing the name_of_select2, of course.

bysystem commented on Aug 22, 2017

Sorry for misunderstanding. Can I do the following on 1 reset button:

$('name1_of_select2', 'name2_of_select2',...'nameN_of_select2).val(null).trigger("change");

KoolReport commented on Aug 22, 2017

No, you do this:

<button onclick="clear()">Clear</button>
<script type="text/javascript">
    function clear()
    {
        $('#name1_of_select2').val(null).trigger("change");
        $('#name2_of_select2').val(null).trigger("change");
        $('#nameN_of_select2').val(null).trigger("change");
    }
</script>
bysystem commented on Aug 22, 2017

Now I got you! Thx a lot! It works well!

KoolReport commented on Aug 22, 2017

Awesome :)

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
solved

Inputs