Sha256: b6b69ecc8588a0ed1ec608117c97e157d57309f5d3313bdff5b5a7534083483d

Contents?: true

Size: 1.25 KB

Versions: 46

Compression:

Stored size: 1.25 KB

Contents

# Prevent non-currency buttons from being pressed
$(document).on 'keydown', "input[type='text'].effective_price", (event) ->
  allowed = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', ',', '.']

  if event.key && event.key.length == 1 && event.metaKey == false && allowed.indexOf(event.key) == -1
    event.preventDefault()

# Assign the hidden input a value of 100x value
$(document).on 'change keyup', "input[type='text'].effective_price", (event) ->
  $input = $(event.target)
  value = $input.val().replace(/,/g, '')

  unless $input.data('include-blank') && value == ''
    value = (parseFloat(value || 0.00) * 100.00).toFixed(0)

  $input.siblings("input[type='hidden']").first().val(value)

# Format the value for display as currency (USD)
$(document).on 'change', "input[type='text'].effective_price", (event) ->
  $input = $(event.target)
  value = $input.siblings("input[type='hidden']").first().val()

  unless $input.data('include-blank') && value == ''
    value = parseInt(value || 0)

  if isNaN(value) == false && value != ''
    value = (value / 100.0) if value != 0

    value = value.toFixed(2).toString()
    value = value.toString().replace(/(\d+)(\d{3})/, '$1'+','+'$2') while (/(\d+)(\d{3})/.test(value))
  else
    value = ''

  $input.val(value)

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
effective_bootstrap-0.0.26 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.0.25 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.0.24 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.0.23 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.0.22 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.0.21 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.0.20 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.0.19 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.0.18 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.0.17 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.0.16 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.0.15 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.0.14 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.0.13 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.0.12 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.0.11 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.0.10 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.0.9 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.0.8 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.0.7 app/assets/javascripts/effective_price/initialize.js.coffee