.type() does not enter a - or + after a valid number in an input of type number
See original GitHub issueCurrent behavior:
Similar to to now closed 6055, if I try to type 123-
into an input of type number, the field only contains 123. This is a bit of an edge case, we use these valid characters to make an invalid number to test field validation messages for our NumberTextField component.
This behavior is a discrepancy between Cypress and manual in Chrome as strings like 123- and 1+1 can be entered manually. Our tests are passing in 3.7 but failing in 3.8.2
Desired behavior:
.type()
allows valid characters to be added to an input of type number even if the positioning of the characters makes the end value invalid.
Steps to reproduce:
use .type('123-')
on an input of type number.
use .type('1+1')
on an input of type number.
Versions
Chrome 79, Windows 10, Cypress 8.3.2
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top Results From Across the Web
<input type="number"> - HTML: HyperText Markup Language
<input> elements of type number are used to let the user enter a number. They include built-in validation to reject non-numerical entries.
Read more >Why does the html input with type "number" allow the letter 'e ...
HTML input number type allows "e/E" because "e" stands for exponential which ... This solution does not prevent copy and pasting (including the...
Read more >Why the number input is the worst input - Stack Overflow Blog
Either way when the number is invalid you can't get the actual value that appears on screen in the <input type="number"> field:
Read more >Check user Input is a Number or String in Python - PYnative
But it doesn't evaluate the data received from the input() ... Output Enter number and hit enter 10 Printing type of input value...
Read more >lightning-input - documentation - Salesforce Developers
Your Salesforce locale is also used to determine if the number you entered is valid. Number Validation. The number field does not let...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yeah, into my fix #6055 I’ve already thought of some corner cases like this one.
Since I didn’t found a satisfying solution, I’ve only resolved the actual issue and didn’t pushed fix futher more.
I would like to share here some of my though:
First, some code lines to look at: https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cy/keyboard.ts#L65 https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cy/keyboard.ts#L262
Basically, Cypress do validation on the typed data regarding of the input type. Why do they do that ? Well, to set the value, Cypess
.type
change the javascript.value
property of the element. So let’s try it with the chrome console.Here is what happen with your examples:
We see two things:
Also, if you manually enter the value “123-” or “1+1” and then try to get the
.value
property of your<input>
element, you’ll will get an empty string as a result.So, we are kind of stuck between the rock and a hard place here.
And I don’t see any “really” satisfying solution. Because:
.type
set the value inside the element will not allow us to set this kind of value (even if no filter was applied on cypress side).I would really like to hear any suggestion about that topic.
I was actually never really able to get the assertion to pass in any version, but the behavior of typing is definitely different from 3.7.0.
index.html
spec.js
3.4.1
3.7.0
3.8.2
Manual typing