Sha256: 241434c3e3c869824e150ed44b32c139130a2ab2b661970dff493b98294192e3

Contents?: true

Size: 1.24 KB

Versions: 13

Compression:

Stored size: 1.24 KB

Contents

hideShippingAddressFields = (shipping_address) ->
  shipping_address.hide().find('input,select').removeProp('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

13 entries across 13 versions & 1 rubygems

Version Path
effective_orders-1.5.5 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee
effective_orders-1.5.4 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee
effective_orders-1.5.3 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee
effective_orders-1.5.2 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee
effective_orders-1.5.1 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee
effective_orders-1.5.0 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee
effective_orders-1.4.8 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee
effective_orders-1.4.7 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee
effective_orders-1.4.6 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee
effective_orders-1.4.5 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee
effective_orders-1.4.4 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee
effective_orders-1.4.3 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee
effective_orders-1.4.2 app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee