Sha256: 84e691c0d49706e6d97ac364ae0808d2022a1066b47ee35d30ecc8dc6f926e63

Contents?: true

Size: 1.06 KB

Versions: 3

Compression:

Stored size: 1.06 KB

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) 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.1.0 lib/watir/elements/date_time_field.rb
watir-7.0.0 lib/watir/elements/date_time_field.rb
watir-7.0.0.beta5 lib/watir/elements/date_time_field.rb