effective_form_inputs 0.8.17 → 0.8.18

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8fd4390225a4f50443ae627c21542ad1d096b088
4
- data.tar.gz: abe4caadf9b054f84439c402324904c3c72cf88c
3
+ metadata.gz: b3766108ff54c4529531ec1691046de43acd86be
4
+ data.tar.gz: 0f005dd2a95a6f60f0a625b95f3f62368e527d99
5
5
  SHA512:
6
- metadata.gz: 916ff497eff505d65e78f9f1630ef416ca5ace3f4f4046c5d7be17a3abb6eb55d143ad1115e9677213af292b588ce89eeac824f09d8e2ad6ee853b87162390a4
7
- data.tar.gz: ebd4ce4227044ccd480a1d541c93dc5f2bbbe061e06d9464d3521633488f1a2d28d92414adca6fa0a134ca6c326143643c81b93167341a8c6389055eddd9b6c9
6
+ metadata.gz: dcec61f890182ec6624b4a61a94ad8f21c28f17af0e2911dd2df8a40a62eea143cf11b3f93636502655f0457a8db94fabec8cf495cea2a4947321abfdcbc8967
7
+ data.tar.gz: b4c4bd9fa158df34e36e1e44539f72ec1dec1dd9104d00a43ef0ee27f4e3bfcb532da18f4c18ee5e80249dc8de7833ace848c74bf9de3cbb573a7c16b2d0a30a
data/README.md CHANGED
@@ -476,6 +476,12 @@ As a SimpleForm input without the input group (glyphicon-usd glyphicon)
476
476
 
477
477
  ### Options
478
478
 
479
+ You can pass `include_blank: true` to allow `nil`. By default `nil`s are convereted, displayed and submitted as `$0.00`.
480
+
481
+ ```ruby
482
+ = f.input :price, :as => :effective_price, :include_blank => true
483
+ ```
484
+
479
485
  There are no javascript options for this input.
480
486
 
481
487
 
@@ -20,14 +20,23 @@ $(document).on 'keydown', "input[type='text'].effective_price", (event) ->
20
20
 
21
21
  # Assign the hidden input a value of 100x value
22
22
  $(document).on 'change keyup', "input[type='text'].effective_price", (event) ->
23
- value = parseFloat($(event.target).val().replace(/,/g, '') || 0.00) * 100.00
24
- $(event.target).siblings("input[type='hidden']").first().val(value.toFixed(0))
23
+ $input = $(event.target)
24
+ value = $input.val().replace(/,/g, '')
25
+
26
+ unless $input.data('include-blank') && value == ''
27
+ value = (parseFloat(value || 0.00) * 100.00).toFixed(0)
28
+
29
+ $input.siblings("input[type='hidden']").first().val(value)
25
30
 
26
31
  # Format the value for display as currency (USD)
27
32
  $(document).on 'change', "input[type='text'].effective_price", (event) ->
28
- value = parseInt($(event.target).siblings("input[type='hidden']").first().val() || 0)
33
+ $input = $(event.target)
34
+ value = $input.siblings("input[type='hidden']").first().val()
35
+
36
+ unless $input.data('include-blank') && value == ''
37
+ value = parseInt(value || 0)
29
38
 
30
- if isNaN(value) == false
39
+ if isNaN(value) == false && value != ''
31
40
  value = (value / 100.0) if value != 0
32
41
 
33
42
  value = value.toFixed(2).toString()
@@ -35,4 +44,4 @@ $(document).on 'change', "input[type='text'].effective_price", (event) ->
35
44
  else
36
45
  value = ''
37
46
 
38
- $(event.target).val(value)
47
+ $input.val(value)
@@ -3,13 +3,17 @@ module Inputs
3
3
  class Input < Effective::FormInput
4
4
  delegate :content_tag, :number_to_currency, :text_field_tag, :hidden_field_tag, :to => :@template
5
5
 
6
+ def default_options
7
+ { include_blank: false }
8
+ end
9
+
6
10
  def default_input_html
7
- {class: 'effective_price numeric', maxlength: 14, autocomplete: 'off'}
11
+ { class: 'effective_price numeric', maxlength: 14, autocomplete: 'off' }
8
12
  end
9
13
 
10
14
  def to_html
11
15
  if options[:input_group] == false
12
- return text_field_tag(field_name, value, tag_options) + hidden_field_tag(field_name, price, id: price_field)
16
+ return text_field_tag(field_name, number_to_currency(value, unit: ''), tag_options) + hidden_field_tag(field_name, price, id: price_field)
13
17
  end
14
18
 
15
19
  content_tag(:div, class: 'input-group') do
@@ -22,6 +26,8 @@ module Inputs
22
26
  end
23
27
 
24
28
  def value
29
+ return nil if (@value == nil && options[:include_blank])
30
+
25
31
  val = (@value || 0) # This is 'super'
26
32
  val.kind_of?(Integer) ? ('%.2f' % (val / 100.0)) : ('%.2f' % val)
27
33
  end
@@ -32,10 +38,18 @@ module Inputs
32
38
  end
33
39
 
34
40
  def price
41
+ return nil if (@value == nil && options[:include_blank])
42
+
35
43
  val = (@value || 0) # This is 'super'
36
44
  val.kind_of?(Integer) ? val : (val * 100.0).to_i
37
45
  end
38
46
 
47
+ def html_options
48
+ super().tap do |html_options|
49
+ html_options['data-include-blank'] = options[:include_blank]
50
+ end
51
+ end
52
+
39
53
  end
40
54
  end
41
55
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveFormInputs
2
- VERSION = '0.8.17'.freeze
2
+ VERSION = '0.8.18'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_form_inputs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.17
4
+ version: 0.8.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect