Skip to content

Insert in type number the same way as strings - #248

Closed
bnjamin wants to merge 1 commit into
rubycdp:mainfrom
bnjamin:insert-numbers-with-events
Closed

bnjamin wants to merge 1 commit into
rubycdp:mainfrom
bnjamin:insert-numbers-with-events

Conversation

@bnjamin

@bnjamin bnjamin commented Oct 31, 2023

Copy link
Copy Markdown

When setting the value in an input of type number, set it the same way as a text, so that we get events(keydown, keypressed, keyup) for each "char" in the number when it is converted to a string

When setting the value in an input of type number, set it the same way as a text, so that we get events(keydown, keypressed, keyup) for each "char" in the number when it is converted to a string
@route

route commented Apr 5, 2026

Copy link
Copy Markdown
Member

I wonder what would be other drivers default behaviour on this. It definitely needs a test in case we want to merge it.
But this requires a bit more research before any action and it was the reason it got stalled.

@route route added the question Further information is requested label Apr 5, 2026
@route

route commented Aug 24, 2026

Copy link
Copy Markdown
Member

Revisited this — thanks for the patch. Unfortunately removing number from the bulk-set branch breaks negative and decimal values, because <input type="number"> sanitizes its .value on every set, not just on blur: an incomplete numeric string like "-" gets silently reset to "" by the browser. The char-by-char loop in the else branch builds the value via node.value + char, so typing -100 goes:

  • set - → sanitized to ""
  • set "" + "1""1"
  • set "10", then "100"

Final value ends up "100" — the sign is silently dropped. Same failure mode for anything starting with . (e.g. .5) or using e notation. This regresses the existing spec covering negative number input (session_spec.rb, "accepts negatives in a number field").

The underlying goal (firing real per-keystroke keydown/keypress/keyup events for number inputs, matching other drivers) is worth doing, but it needs an implementation that accumulates the typed string separately from node.value and only assigns the final value once complete (still firing the synthetic key events per character along the way), plus test coverage for negatives/decimals/scientific notation. Closing this version for now — happy to review a follow-up PR that handles the sanitization case.

Ideally I'd like Cuprite to send real events like Selenium theoretically does but this is a research field to find and compare.

@route route closed this Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

question Further information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants