Class: Kiss::Form::RangeField

Inherits:
Field show all
Defined in:
lib/kiss/form/field.rb

Constant Summary

Constants inherited from Field

Field::CURRENCY_SYMBOLS

Instance Method Summary collapse

Methods inherited from Field

#add_error, #content_tag_html, #debug, #errors_html, #html, #input_tag_html, #method_missing, #param, #require_value, #reset, #tag_html, #tag_start_html, #tip_html, #type, #value, #value_string, #value_to_s

Constructor Details

#initialize(form, *args, &block) ⇒ RangeField

Returns a new instance of RangeField.



528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
# File 'lib/kiss/form/field.rb', line 528

def initialize(form, *args, &block)
  super(form, *args, &block)
  @_type = :range
  
  attrs = args.to_attrs
  text_field_attrs = attrs.merge(
    :style => 'width: 60px'
  )
  text_field_attrs[:html] ||= {}
  
  [:min, :max].each do |key|
    text_field_name = "#{key}_#{attrs.name}"
    text_field_attrs.merge!(
      :name => text_field_name,
      :key => text_field_name.to_sym
    )
    text_field_attrs[:html] = text_field_attrs[:html].clone
    text_field_attrs[:html][:placeholder] = key
    
    instance_variable_set("@_#{key}_field".to_sym, 
      TextField.new(form, text_field_attrs, &block))
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Kiss::Form::Field

Instance Method Details

#element_htmlObject



562
563
564
# File 'lib/kiss/form/field.rb', line 562

def element_html
  @_min_field.element_html + ' to ' + @_max_field.element_html
end

#set_value_to_hash(h) ⇒ Object



566
567
568
569
# File 'lib/kiss/form/field.rb', line 566

def set_value_to_hash(h)
  @_min_field.set_value_to_hash(h)
  @_max_field.set_value_to_hash(h)
end

#set_value_to_object(obj) ⇒ Object



571
572
573
574
# File 'lib/kiss/form/field.rb', line 571

def set_value_to_object(obj)
  @_min_field.set_value_to_object(obj)
  @_max_field.set_value_to_object(obj)
end

#validateObject



552
553
554
555
556
557
558
559
560
# File 'lib/kiss/form/field.rb', line 552

def validate
  @_min_field.validate
  @_max_field.validate
  
  (@_min_field.errors + @_max_field.errors).each do |error|
    add_error(error)
  end
  nil
end