Sha256: c11cf1ded43a287f6e22d90414efa8f3ec8fa0b1076c339fd8830ebbbe711e87

Contents?: true

Size: 1.09 KB

Versions: 3

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

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) do
        execute_js(:setValue, @element, date_time_string)
        execute_js(:fireEvent, @element, :change)
      end
    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

3 entries across 3 versions & 1 rubygems

Version Path
watir-7.2.2 lib/watir/elements/date_time_field.rb
watir-7.2.1 lib/watir/elements/date_time_field.rb
watir-7.2.0 lib/watir/elements/date_time_field.rb