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
- #add_aria_describedby_values(options) ⇒ Object
- #add_aria_labelledby_for_values(tag_value, options) ⇒ Object
- #options_for_rendering ⇒ Object
- #required_field?(field) ⇒ Boolean
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() arr_describedby = [] ['aria'] ||= {} if ["maxlength"] arr_describedby << "maxlength_#{add_default_name_and_id()}" ["aria"]["describedby"] = arr_describedby.join(" ") end arr_describedby << "error_#{add_default_name_and_id()}" if object_has_errors? ["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, ) arr_labelledby= [] ["aria"] ||= {} arr_labelledby << "label_#{add_default_name_and_id()}" if tag_value.nil? ["aria"]["labelledby"] = arr_labelledby.join(" ") else arr_labelledby << "label_#{add_default_name_and_id()}_#{sanitized_value(tag_value)}" ["aria"]["labelledby"] = arr_labelledby.join(" ") end ["aria"]["labelledby"] end |
#options_for_rendering ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/action_view/common_methods.rb', line 11 def = @options.stringify_keys ["size"] = ["maxlength"] unless .key?("size") ["type"] ||= field_type ["value"] = .fetch("value") {value_before_type_cast(object) } unless field_type == "file" ["aria"] ||= {} ["aria"]["required"] = true if required_field?(@method_name) ["aria"]["label"] = "search #{@method_name}" if field_type == "search" @options = add_aria_describedby_values(@options) add_default_name_and_id(@options) end |
#required_field?(field) ⇒ 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 |