Skip to content

Commit

Permalink
init select2 after checkout refresh. Do not remove none-select option.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisnissle committed Apr 11, 2024
1 parent 0067202 commit e304e3c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
1 change: 0 additions & 1 deletion assets/js/static/admin-shipping-rules.min.js

This file was deleted.

43 changes: 20 additions & 23 deletions assets/js/static/pickup-locations.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,27 @@ window.germanized.shipments_pickup_locations = window.germanized.shipments_picku
$( document ).on( 'change', '#pickup_location_field #pickup_location', self.onSelectPickupLocation );

self.afterRefreshCheckout();
}
},

maybeInitSelect2: function() {
if ( $().selectWoo ) {
$( 'select#pickup_location:visible, select#pickup_location:visible' ).each( function() {
var $this = $( this );

// Select2 Enhancement if it exists
if ( $().selectWoo ) {
var wc_gzd_pickup_location_select_select2 = function() {
$( 'select#pickup_location:visible, select#pickup_location:visible' ).each( function() {
var $this = $( this );

var select2_args = {
placeholder: $this.attr( 'data-placeholder' ) || $this.attr( 'placeholder' ) || '',
label: $this.attr( 'data-label' ) || null,
width: '100%',
allowClear: true
};

$this.find( 'option[value=""]' ).remove();

$( this )
.on( 'select2:select', function() {
$( this ).trigger( 'focus' ); // Maintain focus after select https://github.com/select2/select2/issues/4384
} )
.selectWoo( select2_args );
});
var select2_args = {
placeholder: $this.attr( 'data-placeholder' ) || $this.attr( 'placeholder' ) || '',
label: $this.attr( 'data-label' ) || null,
width: '100%',
allowClear: true
};

wc_gzd_pickup_location_select_select2();
}
$( this )
.on( 'select2:select', function() {
$( this ).trigger( 'focus' ); // Maintain focus after select https://github.com/select2/select2/issues/4384
} )
.selectWoo( select2_args );
});
}
},

Expand Down Expand Up @@ -187,6 +182,8 @@ window.germanized.shipments_pickup_locations = window.germanized.shipments_picku

$pickupSelect.val( "" );
}

self.maybeInitSelect2();
},

replaceShippingAddress: function( replacements ) {
Expand Down

0 comments on commit e304e3c

Please sign in to comment.