class UiBibz::Ui::Core::Forms::Numbers::FormulaField

Create a FormulaField

This element is an extend of UiBibz::Ui::Core::Component.

Attributes

Options

You can add HTML attributes using the html_options. You can pass arguments in options attribute:

Signatures

UiBibz::Ui::Core::Forms::Numbers::FormulaField.new(content, options = {}, html_options = {}).render

UiBibz::Ui::Core::Forms::Numbers::FormulaField.new(options = {}, html_options = {}) do
  content
end.render

Examples

UiBibz::Ui::Core::Forms::Numbers::FormulaField.new('value', { formula_field_name: :formula }, { class: 'test' })

UiBibz::Ui::Core::Forms::Numbers::FormulaField.new do
  'value'
end

Helper

formula_field(value, options = {}, html_options = {})

Public Instance Methods

pre_render() click to toggle source

Render html tag

# File lib/ui_bibz/ui/core/forms/numbers/formula_field.rb, line 44
def pre_render
  formula_field_html_tag
end

Private Instance Methods

component_html_classes() click to toggle source
# File lib/ui_bibz/ui/core/forms/numbers/formula_field.rb, line 72
def component_html_classes
  super << %w[formula-field form-control]
end
component_html_options() click to toggle source
# File lib/ui_bibz/ui/core/forms/numbers/formula_field.rb, line 76
def component_html_options
  disabled? ? { disabled: 'disabled' } : {}
end
content_formula_name() click to toggle source
# File lib/ui_bibz/ui/core/forms/numbers/formula_field.rb, line 88
def content_formula_name
  content.to_s.chars.count { |i| i == ']' }.positive? ? content.to_s.gsub(/]$/, '_formula]') : "#{content}_formula"
end
formula_field_alert_glyph() click to toggle source
# File lib/ui_bibz/ui/core/forms/numbers/formula_field.rb, line 80
def formula_field_alert_glyph
  UiBibz::Ui::Core::Icons::Glyph.new('exclamation-triangle', status: :danger).render
end
formula_field_html_tag() click to toggle source
# File lib/ui_bibz/ui/core/forms/numbers/formula_field.rb, line 50
def formula_field_html_tag
  UiBibz::Ui::Core::Forms::Surrounds::SurroundField.new(class: join_classes('formula_field', state, size)).tap do |sf|
    sf.addon @options[:append] unless @options[:append].nil?
    sf.text_field formula_field_name, nil, text_field_formula_html_options
    sf.addon '=', class: 'formula-field-sign'
    sf.text_field content, nil, text_field_input_html_options
    sf.addon formula_field_alert_glyph, { class: 'formula-field-alert' }, { data: { 'bs-toggle': 'tooltip' } }
    sf.addon @options[:prepend] unless @options[:prepend].nil?
  end.render
end
formula_field_name() click to toggle source
# File lib/ui_bibz/ui/core/forms/numbers/formula_field.rb, line 84
def formula_field_name
  options[:formula_field_name] || content_formula_name
end
size() click to toggle source

:lg, :sm or :xs

# File lib/ui_bibz/ui/core/forms/numbers/formula_field.rb, line 97
def size
  "input-group-#{options[:size]}" if options[:size]
end
state() click to toggle source
# File lib/ui_bibz/ui/core/forms/numbers/formula_field.rb, line 92
def state
  states_matching[@options[:status] || @options[:state]] if @options[:status] || @options[:state]
end
states_matching() click to toggle source
# File lib/ui_bibz/ui/core/forms/numbers/formula_field.rb, line 101
def states_matching
  {
    success: 'is-valid',
    danger: 'is-invalid',
    valid: 'is-valid',
    invalid: 'is-invalid',
    active: 'active',
    disabled: 'disabled'
  }
end
text_field_formula_html_options() click to toggle source
# File lib/ui_bibz/ui/core/forms/numbers/formula_field.rb, line 61
def text_field_formula_html_options
  opts = html_options.clone || {}
  opts[:value] = html_options.delete(:formula_field_value)
  opts
end
text_field_input_html_options() click to toggle source
# File lib/ui_bibz/ui/core/forms/numbers/formula_field.rb, line 67
def text_field_input_html_options
  opts = html_options.clone || {}
  opts.merge({ readonly: true, class: 'formula-field-result' })
end