Sha256: 1b740048b990c6f3c054df49b6b1e9981b90f38e279e51f5c6ff22bd99fb0f47
Contents?: true
Size: 1.02 KB
Versions: 87
Compression:
Stored size: 1.02 KB
Contents
module Effective module FormInputs class PercentField < Effective::FormInput def build_input(&block) @builder.hidden_field(name, value: percent_to_integer, id: tag_id + '_value_as_integer') + @template.text_field_tag(name, percent_to_s, options[:input].merge(id: tag_id, name: nil)) end def input_group_options { input_group: { class: 'input-group' }, prepend: content_tag(:span, icon('percent'), class: 'input-group-text') } end def input_html_options { class: 'form-control effective_percent', autocomplete: 'off' } end # This has gotta be a valid pattern def validated?(name) true end private def percent_to_integer return nil unless value value.kind_of?(Integer) ? value : ('%.3f' % (value / 1000.0)) end def percent_to_s return nil unless value str = value.kind_of?(Integer) ? ('%.3f' % (value / 1000.0)) : value.to_s str.gsub('.000', '') end end end end
Version data entries
87 entries across 87 versions & 1 rubygems