Skip to content

Commit

Permalink
Add support for HTML input event (aka oninput) on text fields.
Browse files Browse the repository at this point in the history
The input event is like onchange, but on text fields, it is fired as soon as the value of the field changes, not when the field is blurred. It is a more appropriate event than 'keydown' or 'keyup', which behave unpredictably with paste events, held-down keys, etc.

Support is a little problematic, but it is supported well by Webkit and Firefox, so it seems useful to add here.
  • Loading branch information
whatcould authored and halogenandtoast committed Mar 16, 2012
1 parent fc56a13 commit fc5cba3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion spec/driver_spec.rb
Expand Up @@ -659,6 +659,7 @@
element.addEventListener("keydown", recordEvent);
element.addEventListener("keypress", recordEvent);
element.addEventListener("keyup", recordEvent);
element.addEventListener("input", recordEvent);
element.addEventListener("change", recordEvent);
element.addEventListener("blur", recordEvent);
element.addEventListener("mousedown", recordEvent);
Expand All @@ -678,7 +679,7 @@

let(:keyevents) do
(%w{focus} +
newtext.length.times.collect { %w{keydown keypress keyup} } +
newtext.length.times.collect { %w{keydown keypress keyup input} } +
%w{change blur}).flatten
end

Expand Down
1 change: 1 addition & 0 deletions src/capybara.js
Expand Up @@ -176,6 +176,7 @@ Capybara = {
this.trigger(index, "keydown");
this.keypress(index, false, false, false, false, 0, value.charCodeAt(strindex));
this.trigger(index, "keyup");
this.trigger(index, "input");
}
this.trigger(index, "change");
this.trigger(index, "blur");
Expand Down

0 comments on commit fc5cba3

Please sign in to comment.