Class: Decidim::LegacyFormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Includes:
ActionView::Helpers::OutputSafetyHelper, ActionView::Helpers::TagHelper
Defined in:
lib/decidim/legacy_form_builder.rb

Direct Known Subclasses

FormBuilder

Instance Method Summary collapse

Instance Method Details

#autocomplete(attribute, url, options = {}) ⇒ Object

rubocop:enable Metrics/ParameterLists



96
97
98
99
100
101
102
# File 'lib/decidim/legacy_form_builder.rb', line 96

def autocomplete(attribute, url, options = {})
  field attribute, options do |opts|
    opts.merge!(update_elements: opts[:update_elements],
                min_length: 0, value: object.send(attribute))
    autocomplete_field(attribute, url, opts)
  end
end

#collection_select(attribute, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object

rubocop:disable Metrics/ParameterLists



87
88
89
90
91
92
93
# File 'lib/decidim/legacy_form_builder.rb', line 87

def collection_select(attribute, collection, value_method, text_method, options = {}, html_options = {})
  field attribute, options, html_options do |html_opts|
    html_options[:autocomplete] ||= :off
    super(attribute, collection, value_method, text_method, options,
          html_opts)
  end
end

#date_select(attribute, options = {}, html_options = {}) ⇒ Object



66
67
68
69
70
# File 'lib/decidim/legacy_form_builder.rb', line 66

def date_select(attribute, options = {}, html_options = {})
  field attribute, options, html_options do |html_opts|
    super(attribute, options, html_opts.merge(autocomplete: :off))
  end
end

#datetime_select(attribute, options = {}, html_options = {}) ⇒ Object



60
61
62
63
64
# File 'lib/decidim/legacy_form_builder.rb', line 60

def datetime_select(attribute, options = {}, html_options = {})
  field attribute, options, html_options do |html_opts|
    super(attribute, options, html_opts.merge(autocomplete: :off))
  end
end

#error_for(attribute, options = {}) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
# File 'lib/decidim/legacy_form_builder.rb', line 109

def error_for(attribute, options = {})
  return unless error?(attribute)

  class_name = "form-error is-visible"
  class_name += " #{options[:class]}" if options[:class]

  error_messages = object.errors[attribute].join(", ")
  error_messages = error_messages.html_safe if options[:html_safe_errors]
  (:small, error_messages,
              class: class_name.sub("is-invalid-input", ""))
end

#label(attribute, text = nil, options = {}) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/decidim/legacy_form_builder.rb', line 40

def label(attribute, text = nil, options = {})
  if error?(attribute)
    options[:class] ||= ""
    options[:class] += " is-invalid-label"
  end

  super(attribute, (text || "").html_safe, options)
end

#radio_button(attribute, tag_value, options = {}) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/decidim/legacy_form_builder.rb', line 49

def radio_button(attribute, tag_value, options = {})
  options[:label_options] ||= {}
  label_options = options.delete(:label_options)&.merge!(value: tag_value)
  label_text = options.delete(:label)
  l = label(attribute, label_text, label_options) unless label_text == false
  r = @template.radio_button(@object_name, attribute, tag_value,
                             objectify_options(options))

  "#{r}#{l}".html_safe
end

#select(attribute, choices, options = {}, html_options = {}) ⇒ Object



79
80
81
82
83
84
# File 'lib/decidim/legacy_form_builder.rb', line 79

def select(attribute, choices, options = {}, html_options = {})
  field attribute, options, html_options do |html_opts|
    html_options[:autocomplete] ||= :off
    super(attribute, choices, options, html_opts)
  end
end

#submit(value = nil, options = {}) ⇒ Object



104
105
106
107
# File 'lib/decidim/legacy_form_builder.rb', line 104

def submit(value = nil, options = {})
  options[:class] ||= "button"
  super
end

#time_zone_select(attribute, priorities = nil, options = {}, html_options = {}) ⇒ Object



72
73
74
75
76
77
# File 'lib/decidim/legacy_form_builder.rb', line 72

def time_zone_select(attribute, priorities = nil, options = {}, html_options = {})
  field attribute, options, html_options do |html_opts|
    super(attribute, priorities, options,
          html_opts.merge(autocomplete: :off))
  end
end