Sha256: cb6ee3efd12d670aac02ccfd0d569c9e50574b1f1b2d4c100ba40a4b56bb2301

Contents?: true

Size: 1017 Bytes

Versions: 4

Compression:

Stored size: 1017 Bytes

Contents

module Watir
  class DateTimeField < Input
    #
    # Enter the provided value.
    #

    def set!(date)
      date = ::Time.parse date if date.is_a?(String)

      message = "DateTimeField##{__callee__} only accepts instances of DateTime or Time"
      raise ArgumentError, message unless [DateTime, ::Time].include?(date.class)

      date_time_string = date.strftime('%Y-%m-%dT%H:%M')
      element_call(:wait_for_writable) { execute_js(:setValue, @element, date_time_string) }
    end
    alias set set!
    alias value= set
  end # DateTimeField

  module Container
    def date_time_field(opts = {})
      DateTimeField.new(self, opts.merge(tag_name: 'input', type: 'datetime-local'))
    end

    def date_time_fields(opts = {})
      DateTimeFieldCollection.new(self, opts.merge(tag_name: 'input', type: 'datetime-local'))
    end
  end # Container

  class DateTimeFieldCollection < InputCollection
    private

    def element_class
      DateTimeField
    end
  end # DateTimeFieldCollection
end # Watir

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
watir-7.0.0.beta4 lib/watir/elements/date_time_field.rb
watir-7.0.0.beta3 lib/watir/elements/date_time_field.rb
watir-7.0.0.beta2 lib/watir/elements/date_time_field.rb
watir-7.0.0.beta1 lib/watir/elements/date_time_field.rb