Sha256: 1a523c6603ad574559a965ccaa984f37c026fccd45cd0d38c303e95e59b5ca04
Contents?: true
Size: 1.06 KB
Versions: 116
Compression:
Stored size: 1.06 KB
Contents
# frozen_string_literal: true 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', id: tag_id } 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
116 entries across 116 versions & 1 rubygems