Module: Waiable::CommonMethods

Extended by:
ActiveSupport::Concern
Included in:
Base::CheckBox, Base::DateSelect, Base::RadioButton, Base::Select, Base::TextAria, Base::TextField
Defined in:
lib/action_view/common_methods.rb

Constant Summary collapse

TAG_PREFIXES =
['aria', 'data', :aria, :data].to_set

Instance Method Summary collapse

Instance Method Details

#add_aria_describedby_values(options) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/action_view/common_methods.rb', line 37

def add_aria_describedby_values(options)
  arr_describedby = []
  options['aria'] ||= {}
  if options["maxlength"]
    arr_describedby << "maxlength_#{add_default_name_and_id(options)}"
  options["aria"]["describedby"] = arr_describedby.join(" ")
  end
  arr_describedby << "error_#{add_default_name_and_id(options)}" if object_has_errors?
  options["aria"]["describedby"] = arr_describedby.join(" ")
end

#add_aria_labelledby_for_values(tag_value, options) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/action_view/common_methods.rb', line 24

def add_aria_labelledby_for_values(tag_value, options)
  arr_labelledby= []
  options["aria"] ||= {}
  arr_labelledby << "label_#{add_default_name_and_id(options)}"
  if tag_value.nil?
    options["aria"]["labelledby"] = arr_labelledby.join(" ")
  else
    arr_labelledby << "label_#{add_default_name_and_id(options)}_#{sanitized_value(tag_value)}"
    options["aria"]["labelledby"] = arr_labelledby.join(" ")
  end
  options["aria"]["labelledby"]
end

#options_for_renderingObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/action_view/common_methods.rb', line 11

def options_for_rendering
  options = @options.stringify_keys
  options["size"] = options["maxlength"] unless options.key?("size")
  options["type"] ||= field_type
  options["value"] = options.fetch("value") {value_before_type_cast(object) } unless field_type == "file"
  options["aria"] ||= {}
  options["aria"]["required"] = true if required_field?(@method_name)
options["aria"]["label"] = "search #{@method_name}" if field_type == "search"
  @options = options
  add_aria_describedby_values(@options)
  add_default_name_and_id(@options)
end

#required_field?(field) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/action_view/common_methods.rb', line 49

def required_field?(field)
  object_class = @object_name.classify.constantize
  if object_class.respond_to?(:validators_on)
    object_class.validators_on(field.intern).detect do |validator|
      if validator.is_a? ActiveModel::Validations::PresenceValidator
        validator.is_a? ActiveModel::Validations::PresenceValidator
      elsif validator.is_a? Mongoid::Validatable::PresenceValidator
        validator.is_a? Mongoid::Validatable::PresenceValidator
      end
    end.present?
  end
end