-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
.clear() on an input at maxlength doesn’t work #1002
Comments
Yes this is a known problem. It was first discussed here: #940 (comment) I started working on a solution for this and the text-mask problems but have not finished. |
Any update one this? |
Here's a test (I put this in keyboard_spec.coffee) to prove this bug. I didn't commit this since I didn't know if this is the right place (no other tests found for it "can clear a field with maxlength", ->
Cypress.$('input')
.attr('maxlength', 5)
.val('abcde')
cy.get('input')
.clear()
.should('have.value', '') |
@verheyenkoen there are tests in the type_spec.coffee. If you can, put these tests in there and open a WIP pull request. |
I found there appears to be a lot more bugs related to fields with maxlength, all with the same cause. Special keystrokes like backspace, del, leftarrow, rightarrow,... all seem to be ignored. Don't know about downarrow and uparrow as those only make sense in textareas and don't know if maxlength is a thing there. |
Yup these have been noted / documented before in an issue somewhere. I'll dig and find them. We've been experimenting with moving to native events to bypass all of these issues - although we'll likely still give you a simulated |
Seems I have a similar problem. I have reported it under #2056 |
I'm actively working on this issue and more related to cy.type(). Fixes should be in a patch release coming up |
Is there a workaround how to actually clear a field with maxlength? |
So the problem (for me at least) is when the input filled in filled in with the maximum allowed characters. So what I do, I use jQuery to increase the maxlength parameter like so: |
I have the same problem! |
I've been having some flaky tests where |
@c32hedge can you give an example of a failure, with html and test code? |
@c32hedge Please open a new issue with a reproducible example (HTML + test code). This original issue has been addressed and we have tests around it. Likely you have another case that is very similar with a slight different. |
Is this a Feature or Bug?
A bug.
Current behavior:
Calling
.clear()
on an input with a value as long as itsmaxlength
attribute value leaves the value untouched.Desired behavior:
Calling
.clear()
on an input with a value as long as itsmaxlength
attribute value empties the field.How to reproduce:
maxlength
ton
.value
to a string ofn
characters..clear()
on it.Test code:
Additional Info (images, stack traces, etc)
I suspect the problem to be here:
cypress/packages/driver/src/cypress/keyboard.coffee
Lines 541 to 548 in 324d549
There is a max length, but the value is already at its max length, so it results on a no-op, when it really should clear the field.
The text was updated successfully, but these errors were encountered: