Class: DrgcmsFormFields::NumberField
- Inherits:
-
DrgcmsField
- Object
- DrgcmsField
- DrgcmsFormFields::NumberField
- Defined in:
- app/models/drgcms_form_fields/number_field.rb
Overview
Implementation of number_field DRG CMS form field. Number fields can be formated for display with thousands delimiters and decimal separators and can have currency symbol.
Form options:
-
type:number_field (required) -
name:Field name (required) -
format:Format options -
decimals:No of decimal places -
separator:decimal separator (yes no , .) Default yes if decimals > 0 -
delimiter:Thousands delimiter (yes no , .) Default defind by locals -
currency:Currency sign (yes no sign) Default no. If yes defined by locals -
html:html options which apply to text_field field (optional)
Form example:
10:
name: title
type: number_field
size: 10
format:
decimals: 2
delimiter: false
Instance Attribute Summary
Attributes inherited from DrgcmsField
Class Method Summary collapse
-
.get_data(params, name) ⇒ Object
Return value.
Instance Method Summary collapse
-
#render ⇒ Object
Render text_field field html code.
Methods inherited from DrgcmsField
#hash_to_options, #html, #initialize, #record_text_for, #ro_standard, #set_initial_value, #set_style, #t
Constructor Details
This class inherits a constructor from DrgcmsFormFields::DrgcmsField
Class Method Details
.get_data(params, name) ⇒ Object
Return value. Return nil if input field is empty
77 78 79 80 |
# File 'app/models/drgcms_form_fields/number_field.rb', line 77 def self.get_data(params, name) return 0 if params['record'][name].blank? params['record'][name].match('.') ? BigDecimal.new(params['record'][name]) : Integer.new(params['record'][name]) end |
Instance Method Details
#render ⇒ Object
Render text_field field html code
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/models/drgcms_form_fields/number_field.rb', line 54 def render return ro_standard if @readonly set_initial_value # record = record_text_for(@yaml['name']) @yaml['html'] ||= {} @yaml['html']['class'] = 'dc-number' @yaml['html']['data-decimal'] = @yaml.dig('format','decimal') || 2 @yaml['html']['data-delimiter'] = @yaml.dig('format','delimiter') || I18n.t('number.currency.format.delimiter') @yaml['html']['data-separator'] = @yaml.dig('format','separator') || I18n.t('number.currency.format.separator') # @yaml['html']['data-currency'] = @yaml.dig('format','currency') == 'yes' ? I18n.t('number.currency.format.currency') : @yaml.dig('format','currency') value = @record[@yaml['name']] || 0 @html << @parent.hidden_field( record, @yaml['name'], value: value ) @yaml['html']['value'] = @parent.dc_format_number(value, @yaml['html']['data-decimal'], @yaml['html']['data-separator'], @yaml['html']['data-delimiter'] ) @html << @parent.text_field( nil,"record_#{@yaml['name']}1", @yaml['html']) self end |