Jems
Jems

Reputation: 1706

JQuery reset select2 in modal

I have tried the way like this to reset select2 in my modal, but It does not work.

$(".payment-method").select2('data', null);

<div class="modal-body"> 
                  <form class="form-horizontal" id="category-form" enctype="multipart/form-data">
                  {{ csrf_field() }}
                        <div class="col-xs-12 col-sm-6 col-md-6">
                          <label>Payment Methods (Untuk kebutuhan tertentu)</label>
                          <div class="dropdown">
                            <select class="form-control payment-method" name="paymentType" multiple="multiple" data-placeholder="Select the payment method">
                              <option value="1">cash</option>
                              <option value="2">credit</option>
                              <option value="3">debit</option>
                            </select>
                          </div>
                        </div>
                      </div>

                </form>
                </div> 

Upvotes: 1

Views: 5209

Answers (2)

Jems
Jems

Reputation: 1706

$(".payment-method").val([]).trigger("change"); //Answered by apokryfos

Upvotes: 3

Hasan Shahriar
Hasan Shahriar

Reputation: 478

If you using Select2 4.x just trigger change.select2

$('.payment-method').val(1).trigger('change.select2');

Upvotes: 0

Related Questions