1
0
Fork 0
mirror of https://github.com/thoughtbot/capybara-webkit synced 2023-03-27 23:22:28 -04:00

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.
This commit is contained in:
David Reese 2012-02-12 13:18:40 -05:00 committed by Matthew Mongeau
parent fc56a13a6b
commit fc5cba3ee0
2 changed files with 3 additions and 1 deletions

View file

@ -659,6 +659,7 @@ describe Capybara::Driver::Webkit do
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 @@ describe Capybara::Driver::Webkit do
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 file

@ -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");