Sha256: 942969ea6c3cdebbd16e9338d2ef5dddb9a1d008dde0b06d254d9a3de164ea36

Contents?: true

Size: 1.24 KB

Versions: 25

Compression:

Stored size: 1.24 KB

Contents

hideShippingAddressFields = (shipping_address) ->
  shipping_address.hide().find('input,select').removeAttr('required')

showShippingAddressFields = (shipping_address) ->
  shipping_address.show().find("input:not([name$='[address2]']),select:not([name$='[state_code]'])").prop('required', true)

initShippingAddressFields = ->
  effective_order = $('.effective-order').first()

  if effective_order.length > 0
    shipping_address_same_as_billing = effective_order.find('#effective_order_shipping_address_same_as_billing')
    shipping_address = effective_order.find('.shipping_address_fields')

    if shipping_address_same_as_billing.length > 0 && shipping_address.length > 0
      if shipping_address_same_as_billing.is(':checked')
        hideShippingAddressFields(shipping_address)
      else
        showShippingAddressFields(shipping_address)

$ -> initShippingAddressFields()
$(document).on 'page:change', -> initShippingAddressFields()

$(document).on 'change', '#effective_order_shipping_address_same_as_billing', (event) ->
  obj = $(event.currentTarget)
  shipping_address = obj.closest('form').find('.shipping_address_fields')

  if obj.is(':checked')
    hideShippingAddressFields(shipping_address)
  else
    showShippingAddressFields(shipping_address)

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
effective_orders-2.1.5 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee
effective_orders-2.1.4 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee
effective_orders-2.1.3 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee
effective_orders-2.1.2 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee
effective_orders-2.1.1 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee
effective_orders-2.1.0 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee
effective_orders-2.0.1 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee
effective_orders-2.0.0 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee
effective_orders-1.8.1 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee
effective_orders-1.8.0 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee
effective_orders-1.7.5 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee
effective_orders-1.7.4 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee
effective_orders-1.7.3 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee
effective_orders-1.7.2 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee
effective_orders-1.7.1 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee
effective_orders-1.7.0 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee
effective_orders-1.6.6 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee
effective_orders-1.6.5 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee
effective_orders-1.6.4 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee
effective_orders-1.6.3 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee