diff --git a/assets/js/frontend/country-select.js b/assets/js/frontend/country-select.js
index dc0901070ae..259f592c527 100644
--- a/assets/js/frontend/country-select.js
+++ b/assets/js/frontend/country-select.js
@@ -101,27 +101,17 @@ jQuery( function( $ ) {
if ( states[ country ] ) {
if ( $.isEmptyObject( states[ country ] ) ) {
+ var $newstate = $( '' )
+ .prop( 'id', input_id )
+ .prop( 'name', input_name )
+ .prop( 'placeholder', placeholder )
+ .addClass( 'hidden' );
$parent.hide().find( '.select2-container' ).remove();
- $statebox.replaceWith(
- ''
- );
+ $statebox.replaceWith( $newstate );
$( document.body ).trigger( 'country_to_state_changed', [ country, $wrapper ] );
} else {
-
- var options = '',
- state = states[ country ];
-
- for ( var index in state ) {
- if ( state.hasOwnProperty( index ) ) {
- options = options + '';
- }
- }
+ var state = states[ country ],
+ $defaultOption = $( '' ).text( wc_country_select_params.i18n_select_state_text );
if ( ! placeholder ) {
placeholder = wc_country_select_params.i18n_select_state_text;
@@ -130,37 +120,37 @@ jQuery( function( $ ) {
$parent.show();
if ( $statebox.is( 'input' ) ) {
- // Change for select
- $statebox.replaceWith(
- ''
- );
+ $newstate = $( '' )
+ .prop( 'id', input_id )
+ .prop( 'name', input_name )
+ .data( 'placeholder', placeholder )
+ .addClass( 'state_select' );
+ $statebox.replaceWith( $newstate );
$statebox = $wrapper.find( '#billing_state, #shipping_state, #calc_shipping_state' );
}
- $statebox.html( '' + options );
+ $statebox.empty().append( $defaultOption );
+
+ $.each( state, function( index ) {
+ var $option = $( '' )
+ .prop( 'value', index )
+ .text( state[ index ] );
+ $statebox.append( $option );
+ } );
+
$statebox.val( value ).change();
$( document.body ).trigger( 'country_to_state_changed', [country, $wrapper ] );
}
} else {
-
if ( $statebox.is( 'select, input[type="hidden"]' ) ) {
+ var $newstate = $( '' )
+ .prop( 'id', input_id )
+ .prop( 'name', input_name )
+ .prop( 'placeholder', placeholder )
+ .addClass( 'input-text' );
$parent.show().find( '.select2-container' ).remove();
- $statebox.replaceWith(
- ''
- );
+ $statebox.replaceWith( $newstate );
$( document.body ).trigger( 'country_to_state_changed', [country, $wrapper ] );
}
}