Class: FormCandy::Field::Money
- Inherits:
-
Base
- Object
- Base
- FormCandy::Field::Money
- Defined in:
- lib/caisson/helpers/form/field/money.rb
Instance Method Summary collapse
-
#build(name, value, options = {}) ⇒ Object
************************************************************************************* PUBLIC INSTANCE METHODS *************************************************************************************.
- #format_value(value, decimal) ⇒ Object
Instance Method Details
#build(name, value, options = {}) ⇒ Object
************************************************************************************* PUBLIC INSTANCE METHODS *************************************************************************************
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/caisson/helpers/form/field/money.rb', line 9 def build(name, value, ={}) = decimal = [:decimal] ? .delete(:decimal).to_i : 2 [:class].gsub!('text-field', 'money-field') ["data-validations"] = [["data-validations"], 'numeric'].compact.join(' ') ["data-decimal"] = decimal content = text_field_tag('formatted-' + name, format_value(value, decimal), ) content += content_tag(:span, '$', class: 'symbol currency') content += hidden_field_tag(name, value, id: nil, class: 'dbdata') return content.html_safe end |
#format_value(value, decimal) ⇒ Object
25 26 27 |
# File 'lib/caisson/helpers/form/field/money.rb', line 25 def format_value(value, decimal) value.blank? ? '' : sprintf("%0.0#{decimal}f", (value.to_f / (10 ** decimal)).round(decimal)).gsub('.', ',') end |