Module: Phlexi::Form::Options::Errors

Included in:
Builder
Defined in:
lib/phlexi/form/options/errors.rb

Instance Method Summary collapse

Instance Method Details

#can_show_errors?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/phlexi/form/options/errors.rb', line 24

def can_show_errors?
  options[:error] != false
end

#custom_error(error) ⇒ Object



7
8
9
10
# File 'lib/phlexi/form/options/errors.rb', line 7

def custom_error(error)
  options[:error] = error
  self
end

#errorObject



12
13
14
# File 'lib/phlexi/form/options/errors.rb', line 12

def error
  error_text if has_errors?
end

#full_errorObject



16
17
18
# File 'lib/phlexi/form/options/errors.rb', line 16

def full_error
  full_error_text if has_errors?
end

#has_errors?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/phlexi/form/options/errors.rb', line 20

def has_errors?
  object_with_errors? || !object && has_custom_error?
end

#object_valid?Boolean

Determines if the associated object is in a valid state

An object is considered valid if it is persisted and has no errors.

Returns:

  • (Boolean)

    true if the object is persisted and has no errors, false otherwise



41
42
43
44
# File 'lib/phlexi/form/options/errors.rb', line 41

def object_valid?
  object.respond_to?(:persisted?) && object.persisted? &&
    object.respond_to?(:errors) && !object.errors.empty?
end

#show_errors?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/phlexi/form/options/errors.rb', line 28

def show_errors?
  can_show_errors? && has_errors?
end

#valid?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/phlexi/form/options/errors.rb', line 32

def valid?
  !has_errors? && has_value?
end