Module: ActionValidator::FormHelper

Defined in:
app/helpers/action_validator/form_helper.rb

Overview

Form helpers that will render a standard Rails ‘form_for` or `form_with` that has all of the necessary attributes added for the ActionValidator Stimulus controller to work.

Instance Method Summary collapse

Instance Method Details

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

Renders an unstyled div with the correct Stimulus data attributes on it.



27
28
29
30
31
32
33
# File 'app/helpers/action_validator/form_helper.rb', line 27

def validator_error(attribute, options = {})
  options[:data] ||= {}
  options[:data][ActionValidator::STIMULUS_SELECTORS[:target]] = :error
  options[:data][:attribute] = attribute

  tag.div(id: attribute, **options)
end

#validator_form_for(record, options = {}, &block) ⇒ Object

A wrapper around the Rails form_for helper. This method can be used exactly the same as the standard Rails helper.



10
11
12
13
14
# File 'app/helpers/action_validator/form_helper.rb', line 10

def validator_form_for(record, options = {}, &block)
  merge_form_options(options)

  form_for(record, options, &block)
end

#validator_form_with(model: false, scope: nil, url: nil, format: nil, **options, &block) ⇒ Object

A wrapper around the Rails form_with helper. This method can be used exactly the same as the standard Rails helper.



19
20
21
22
23
# File 'app/helpers/action_validator/form_helper.rb', line 19

def validator_form_with(model: false, scope: nil, url: nil, format: nil, **options, &block)
  merge_form_options(options)

  form_with(model: model, scope: scope, url: url, format: format, **options, &block)
end