question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot type into a datetime-local input field

See original GitHub issue

Current behavior:

The input field doesn’t update with a value when you type in text

Desired behavior:

The value should appear in the input

How to reproduce:

Test code:

Typescript:

cy.get("input[type='datetime-local']").type("1");

Additional Info (images, stack traces, etc)

I can see from the log it correctly “yields” the input element. It just doesn’t visually display anything in the input box (when the type command executes).

  • Operating System: Win 10
  • Cypress Version: 2.0.3
  • Browser Version: Chrome 64

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
DiederikvandenBcommented, Jan 22, 2019

@cypressProj I am going to make a wild guess here, and assume you use ReactJS. I had the same issue you described. I figured that this was caused by React, because we are using React controlled inputs.

This Stackoverflow answer pointed me in the right direction: https://stackoverflow.com/a/46012210/1221091

My code:

support/setDate.js

export default (input, value) => {
  const nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set;
  nativeInputValueSetter.call(input, value);

  const event = new Event('input', { bubbles: true });
  input.dispatchEvent(event);
};

And then I use it like this:

import setDate from 'support/setDate';

cy.get('@key_dropoff_at')
      .then(input => setDate(input[0], '2018-12-12T00:00'));
2reactions
barryskalcommented, Apr 30, 2018

This was pretty frustrating to fix, but I managed to come up with the following work around that played nicely with redux form.

        cy
          .get('#dateField')
          .click()
          .then(input => {
            input[0].dispatchEvent(new Event('input', { bubbles: true }))
            input.val('2017-04-30T13:00')
          })
          .click()
Read more comments on GitHub >

github_iconTop Results From Across the Web

Bind an input with type datetime-local to a Date property in ...
Demo Plnkr. You can bind to a date using the following format: yyyy-MM-ddTHH:mm , which you can also get from date.toISOString().slice(0,16) (the slice ......
Read more >
<input type="datetime-local"> - HTML - MDN Web Docs
One thing the datetime-local input type doesn't provide is a way to set the time zone and/or locale of the date/time control. This...
Read more >
HTML Input Types - W3Schools
Here are the different input types you can use in HTML: ... <input type="text"> defines a single-line text input field: ... Input Type...
Read more >
Text field - Shopify Polaris
A text field is an input field that merchants can type into. It has a range of options and supports several text formats...
Read more >
Anyone using input fields of type "datetime-local"? How to get ...
I'd love to use <input type="datetime-local" in my Elm app, but the output of that field seems to be of the form “YYYY-MM-DDTHH:MM”, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found