Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to cy.type() for inputs of type date, time, month, week #27

Closed
jennifer-shehane opened this issue Apr 20, 2015 · 14 comments
Closed
Labels
pkg/driver This is due to an issue in the packages/driver directory type: bug
Milestone

Comments

@jennifer-shehane
Copy link
Member

jennifer-shehane commented Apr 20, 2015

When I use command cy.type() for inputs of type date, time, month, and week the value is not updated for the input. The type command needs to do special logic to inject the values (or do special click / selects / types) due to the formatting / dropdown nature of these inputs.

Date Example

<input name="birthday" type="date">
cy.get("input[name='birthday']").type("11151985").should("have.value", "1985-11-15")

This example's assertion will fail and say expected input to have value of '1985-11-15', but got ''

Time Example

<input name="appt" type="time">
cy.get("input[name='appt']").type("1215am").should("have.value", "00:15:00")

This example's assertion will fail and say expected input to have value of '00:15:00', but got ''

Month Example

<input id="month" type="month">
cy.get("#month").type("February 2012").should("have.value", "February 2012")

This example's assertion will fail and say expected '<input#month.form-control>' to have value 'February 2012', but the value was ''

Week Example

<input id="week" type="week">
cy.get("#week").type("20, 2016").should("have.value", "February 2012")

This example's assertion will fail and say expected '<input#week.form-control>' to have value '20, 2016', but the value was ''

@jennifer-shehane jennifer-shehane added the type: enhancement Requested enhancement of existing feature label Apr 21, 2015
@jennifer-shehane jennifer-shehane changed the title Add support to cy.type() for inputs of type date and time Add support to cy.type() for inputs of type date, time, month, week May 12, 2016
@jennifer-shehane jennifer-shehane added type: bug and removed type: enhancement Requested enhancement of existing feature labels May 12, 2016
@wavesoft
Copy link

wavesoft commented Mar 3, 2017

I also have an issue with .type on type=number input. In my case including . to the expression does the same thing as {selectall}.

For example: .type('0.2') results in 2

@jennifer-shehane jennifer-shehane added the pkg/driver This is due to an issue in the packages/driver directory label Mar 21, 2017
@ashercoren
Copy link

Please fix this...

@thomas-p-wilson
Copy link

Will also note that the docs at https://docs.cypress.io/v1.0/docs/type#section-known-issues seem to be inconsistent with the behaviour I'm seeing. The docs suggest that to enter a date I may simply write cy.get('<element>').type('17/04/2017'), wherein I am typing the fully-formatted value of the input. However, doing so yields the same result as @jennifer-shehane, namely expected input to have value of '17-04-2017', but got ''.

If the docs are in fact out of sync with the behaviour of Cypress currently, it might be a good idea to update the docs to reflect that. If the docs are suggesting this might be the expected fix, then it might also be good to note that as well.

Of course, it would also be good to just get the issue fixed as well. Seems to me that as I can enter dates/numbers/special fields by hand just by tabbing and typing, the same should be easily accomplished with Cypress. I might try mucking about with tabbing a bit to see if it works with these special cases at all.

@thomas-p-wilson
Copy link

Will also point out that it has been 13 months since @jennifer-shehane brought this issue to light. Has there been any movement on this?

@brian-mann
Copy link
Member

There has actually. In fact this will be fixed in the next release (0.20.0)

@thomas-p-wilson
Copy link

Very cool! Thanks for the update @brian-mann. I presume it will be fixed in accordance with what the docs already specify? Namely, it'll require entering the preformatted final value?

@brian-mann
Copy link
Member

Correct. It will require entering the final value that will actually get set per the spec. We'll validate it up front and fire the keystrokes, but the value won't appear until its all done.

@thomas-p-wilson
Copy link

thomas-p-wilson commented May 23, 2017 via email

@RandallKent
Copy link
Contributor

The code for this is done, but this has yet to be released. We'll update the issue and reference the changelog when it's released.

@brian-mann
Copy link
Member

Fixed in 0.20.0

@cypress
Copy link

cypress bot commented Oct 12, 2021



Test summary

115 0 0 0


Run details

Project circleci-orb-parallel-example
Status Passed
Commit 72c90ee69f
Started Oct 12, 2021 2:50 AM
Ended Oct 12, 2021 2:52 AM
Duration 01:46 💡
OS Linux Debian - 10.6
Browser Electron 93

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@sharandaa
Copy link

I still have an issue with this. If I let the user type in a date in the preformatted final value, I still get this error when I use should(): expected '<tr#opening_date_level_1..opening_date_container>' to have value '01-12-2022', but the value was ''.

@carloscfcortez
Copy link

@sharandaa try to use that

cy.get('get-your-input').invoke('removeAttr', 'type')type('2022-12-01{enter}').trigger('change');

cy.get('get-your-input').invoke('attr', 'value', '2022-12-01').trigger('change');

cy.get('get-your-input').invoke('attr', 'type', 'date');

@anilpujaraofficial
Copy link

Screenshot from 2023-05-19 14-09-04
how to input date

@cypress cypress bot mentioned this issue Aug 11, 2023
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg/driver This is due to an issue in the packages/driver directory type: bug
Projects
None yet
Development

No branches or pull requests

10 participants