Permalink
Browse files

Add support for HTML input event (aka oninput) on text fields.

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...
1 parent fc56a13 commit fc5cba3ee0aad5acf07886e8899a7eca5c0f4f7a @whatcould whatcould committed with halogenandtoast Feb 12, 2012
Showing with 3 additions and 1 deletion.
  1. +2 −1 spec/driver_spec.rb
  2. +1 −0 src/capybara.js
View
@@ -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);
@@ -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
View
@@ -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");

0 comments on commit fc5cba3

Please sign in to comment.