Reputation: 7291
I need to reset couple of select2 select element. Currently i am doing it as follows
$("#ItemId").select2("val", "");
$("#PermanentDistrictId").select2("val", "");
$("#PermanentThanaId").select2("val", "");
$("#PresentDistrictId").select2("val", "");
$("#PresentThanaId").select2("val", "");
$("#OccupationId").select2("val", "");
$("#GenderId").select2("val", "");
But i would like to do it in single function like as follows-
ParticularForm.AllSelectElements.select2("val", "");
I am asking here as because my javascript skill is very poor. So, I need your help.
Thank you.
Upvotes: 2
Views: 4611
Reputation: 91
Just trigger
the change.select2
event with .trigger('change.select2')
$(document).on('click','[type="reset"]', function (e){
$(this)
.closest('form')
.find('select')
.val(null)
.trigger('change.select2');
});
Upvotes: 1
Reputation: 227190
Your ParticularForm.AllSelectElements
can be done as follows:
$('#yourform select').select2("val", "");
This selects all <select>
elements inside #yourform
.
Upvotes: 3