Class: Webrat::MultipleSelectField

Inherits:
Field show all
Defined in:
lib/webrat/core/elements/field.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from Field

#value

Attributes inherited from Element

#element

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Field

#disabled?, field_class, field_classes, #id, inherited, #initialize, #label_text, load, #raise_error_if_disabled, xpath_search_excluding_hidden

Methods inherited from Element

#initialize, #inspect, load, load_all, #path

Constructor Details

This class inherits a constructor from Webrat::Field

Class Method Details

.xpath_searchObject



437
438
439
# File 'lib/webrat/core/elements/field.rb', line 437

def self.xpath_search
  [".//select[@multiple='multiple']"]
end

Instance Method Details

#optionsObject



441
442
443
# File 'lib/webrat/core/elements/field.rb', line 441

def options
  @options ||= SelectOption.load_all(@session, @element)
end

#set(value) ⇒ Object



445
446
447
# File 'lib/webrat/core/elements/field.rb', line 445

def set(value)
  @value << value
end

#to_paramObject

We have to overide how the uri string is formed when dealing with multiples Where normally a select field might produce name=value with a multiple, we need to form something like name[]=value1&name=value2



456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
# File 'lib/webrat/core/elements/field.rb', line 456

def to_param
  return nil if disabled?

  uri_string = @value.collect {|value| "#{name}=#{CGI.escape(value)}"}.join("&")
  params = case Webrat.configuration.mode
  when :rails
    parse_rails_request_params(uri_string)
  when :merb
    ::Merb::Parse.query(uri_string)
  else
    { name => @value }
  end

  unescape_params(params)
end

#unset(value) ⇒ Object



449
450
451
# File 'lib/webrat/core/elements/field.rb', line 449

def unset(value)
  @value.delete(value)
end