Sha256: 1d16490b37ad081d3a12dbbb3b86c10734273a4eb5ed569c3d5e6504d549a652

Contents?: true

Size: 1.33 KB

Versions: 12

Compression:

Stored size: 1.33 KB

Contents

// eslint-disable-next-line camelcase, no-unused-vars
function update_state(region, done) {
  'use strict'

  var countryId = $('#' + region + 'country select').val()
  var stateContainer = $('#' + region + 'state').parent()
  var stateSelect = $('#' + region + 'state select')
  var stateInput = $('#' + region + 'state input.state_name')

  $.get(Spree.routes.states_search + '?country_id=' + countryId, function (data) {
    var states = data.states
    var statesRequired = data.states_required
    if (states.length > 0) {
      stateSelect.html('')
      var statesWithBlank = [{
        name: '',
        id: ''
      }].concat(states)
      $.each(statesWithBlank, function (_pos, state) {
        var opt = $(document.createElement('option'))
          .prop('value', state.id)
          .html(state.name)
        stateSelect.append(opt).trigger('change')
      })
      stateSelect.prop('disabled', false).show()
      stateSelect.select2()
      stateInput.hide().prop('disabled', true)
      stateContainer.show()
    } else {
      stateSelect.val(null).trigger('change')
      if (stateSelect.data('select2')) {
        stateSelect.select2('destroy')
      }
      stateSelect.hide()
      if (statesRequired) {
        stateInput.prop('disabled', false).show()
      } else {
        stateContainer.hide()
      }
    }

    if (done) done()
  })
};

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
spree_backend-4.2.7 app/assets/javascripts/spree/backend/address_states.js
spree_backend-4.2.6 app/assets/javascripts/spree/backend/address_states.js
spree_backend-4.2.5 app/assets/javascripts/spree/backend/address_states.js
spree_backend-4.2.4 app/assets/javascripts/spree/backend/address_states.js
spree_backend-4.2.3.1 app/assets/javascripts/spree/backend/address_states.js
spree_backend-4.2.3 app/assets/javascripts/spree/backend/address_states.js
spree_backend-4.2.2 app/assets/javascripts/spree/backend/address_states.js
spree_backend-4.2.1 app/assets/javascripts/spree/backend/address_states.js
spree_backend-4.2.0 app/assets/javascripts/spree/backend/address_states.js
spree_backend-4.2.0.rc5 app/assets/javascripts/spree/backend/address_states.js
spree_backend-4.2.0.rc4 app/assets/javascripts/spree/backend/address_states.js
spree_backend-4.2.0.rc3 app/assets/javascripts/spree/backend/address_states.js