Class: Effective::FormBuilderInputs::EffectivePrice
- Inherits:
-
Effective::FormBuilderInput
- Object
- Effective::FormBuilderInput
- Effective::FormBuilderInputs::EffectivePrice
- Defined in:
- app/models/effective/form_builder_inputs/effective_price.rb
Instance Method Summary collapse
- #default_input_html ⇒ Object
- #default_options ⇒ Object
- #html_options ⇒ Object
- #price ⇒ Object
-
#price_field ⇒ Object
These two are for the hidden input.
- #to_html ⇒ Object
- #value ⇒ Object
Methods inherited from Effective::FormBuilderInput
#field_name, #initialize, #js_options, #options
Constructor Details
This class inherits a constructor from Effective::FormBuilderInput
Instance Method Details
#default_input_html ⇒ Object
10 11 12 |
# File 'app/models/effective/form_builder_inputs/effective_price.rb', line 10 def default_input_html { class: 'effective_price numeric', maxlength: 14, autocomplete: 'off' } end |
#default_options ⇒ Object
6 7 8 |
# File 'app/models/effective/form_builder_inputs/effective_price.rb', line 6 def { include_blank: false } end |
#html_options ⇒ Object
47 48 49 50 51 |
# File 'app/models/effective/form_builder_inputs/effective_price.rb', line 47 def super().tap do || ['data-include-blank'] = [:include_blank] end end |
#price ⇒ Object
40 41 42 43 44 45 |
# File 'app/models/effective/form_builder_inputs/effective_price.rb', line 40 def price return nil if (@value == nil && [:include_blank]) val = (@value || 0) # This is 'super' val.kind_of?(Integer) ? val : (val * 100.0).to_i end |
#price_field ⇒ Object
These two are for the hidden input
36 37 38 |
# File 'app/models/effective/form_builder_inputs/effective_price.rb', line 36 def price_field "#{field_name.parameterize.gsub('-', '_')}_value_as_integer" end |
#to_html ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/models/effective/form_builder_inputs/effective_price.rb', line 14 def to_html if [:input_group] == false return text_field_tag(field_name, number_to_currency(value, unit: ''), ) + hidden_field_tag(field_name, price, id: price_field) end content_tag(:div, class: 'input-group') do content_tag(:span, '$', class: 'input-group-addon') do content_tag(:i, '', class: 'glyphicon glyphicon-usd').html_safe end + text_field_tag(field_name, number_to_currency(value, unit: ''), ) + hidden_field_tag(field_name, price, id: price_field) end end |
#value ⇒ Object
28 29 30 31 32 33 |
# File 'app/models/effective/form_builder_inputs/effective_price.rb', line 28 def value return nil if (@value == nil && [:include_blank]) val = (@value || 0) # This is 'super' val.kind_of?(Integer) ? ('%.2f' % (val / 100.0)) : ('%.2f' % val) end |