Class: FieldableForm::TextField

Inherits:
Field
  • Object
show all
Defined in:
lib/fieldable_form/text_field.rb

Constant Summary

Constants inherited from Field

Field::DESCENDANTS

Instance Method Summary collapse

Methods inherited from Field

new

Instance Method Details

#max_lengthObject



64
65
66
# File 'lib/fieldable_form/text_field.rb', line 64

def max_length
  options['max_length']
end

#max_length=(value) ⇒ Object



68
69
70
71
# File 'lib/fieldable_form/text_field.rb', line 68

def max_length=(value)
  options_will_change! if options['max_length'] != value
  options['max_length'] = value
end

#min_lengthObject



55
56
57
# File 'lib/fieldable_form/text_field.rb', line 55

def min_length
  options['min_length']
end

#min_length=(value) ⇒ Object



59
60
61
62
# File 'lib/fieldable_form/text_field.rb', line 59

def min_length=(value)
  options_will_change! if options['min_length'] != value
  options['min_length'] = value
end

#number_onlyObject



46
47
48
# File 'lib/fieldable_form/text_field.rb', line 46

def number_only
  options['number_only']
end

#number_only=(value) ⇒ Object



50
51
52
53
# File 'lib/fieldable_form/text_field.rb', line 50

def number_only=(value)
  options_will_change! if options['number_only'] != value
  options['number_only'] = value
end

#render_methodObject

Overrides



10
11
12
# File 'lib/fieldable_form/text_field.rb', line 10

def render_method
  :text_field
end

#render_optionsObject

Overrides



15
16
17
# File 'lib/fieldable_form/text_field.rb', line 15

def render_options
  [name]      
end

#requiredObject



37
38
39
# File 'lib/fieldable_form/text_field.rb', line 37

def required
  options['required']
end

#required=(value) ⇒ Object



41
42
43
44
# File 'lib/fieldable_form/text_field.rb', line 41

def required=(value)
  options_will_change! if options['required'] != value
  options['required'] = value
end

#validatorsObject

Overrides



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

def validators
  min = integerize_or_nil(min_length)
  max = integerize_or_nil(max_length)

  validators = []
  validators << ActiveModel::Validations::PresenceValidator.new(:attributes => name) if required == '1'
  validators << ActiveModel::Validations::NumericalityValidator.new(:attributes => name, :only_integer => true) if number_only == '1'
  validators << ActiveModel::Validations::LengthValidator.new(:attributes => name, :minimum => min ) if min
  validators << ActiveModel::Validations::LengthValidator.new(:attributes => name, :maximum => max ) if max
  validators
end

#view_partial_nameObject

Overrides



20
21
22
# File 'lib/fieldable_form/text_field.rb', line 20

def view_partial_name
  'text_field'
end