Class: ParsleySimpleForm::Constraints::Basics::RequiredConstraint

Inherits:
ParsleySimpleForm::Constraints::BaseConstraint show all
Defined in:
lib/parsley_simple_form/constraints/basics/required_constraint.rb

Instance Method Summary collapse

Methods inherited from ParsleySimpleForm::Constraints::BaseConstraint

#initialize, #input_id, #input_type

Constructor Details

This class inherits a constructor from ParsleySimpleForm::Constraints::BaseConstraint

Instance Method Details

#html_attributesObject



17
18
19
# File 'lib/parsley_simple_form/constraints/basics/required_constraint.rb', line 17

def html_attributes
  {"data-parsley-required-message".to_sym => I18n::translate('form_validation.message.required')}
end

#match?Boolean

Check for this attributes: data-required=“true”, class=“required” or required=“required”

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
# File 'lib/parsley_simple_form/constraints/basics/required_constraint.rb', line 8

def match?
  return false if @options.nil?

  input_html = @options[:input_html]
  !input_html.nil? && (!input_html[:required].nil? || !input_html[:'data-required'].nil? || 
    (!input_html[:class].nil? && input_html[:class].include?('required')) || !@options[:required].nil?) 
      
end