Browse files

Trigger change event on checkbox and radio button when checked state …

…is changed
  • Loading branch information...
1 parent d7f491d commit 465e5edb1298df9bd237d95b680b27c4451f82d9 Vasily Reys committed with jferris May 27, 2011
Showing with 3 additions and 2 deletions.
  1. +2 −2 spec/driver_spec.rb
  2. +1 −0 src/capybara.js
View
4 spec/driver_spec.rb
@@ -467,12 +467,12 @@
it "triggers radio input events" do
subject.find("//input[@type='radio']").first.set(true)
- subject.find("//li").map(&:text).should == %w(click)
+ subject.find("//li").map(&:text).should == %w(click change)
end
it "triggers checkbox events" do
subject.find("//input[@type='checkbox']").first.set(true)
- subject.find("//li").map(&:text).should == %w(click)
+ subject.find("//li").map(&:text).should == %w(click change)
end
end
View
1 src/capybara.js
@@ -105,6 +105,7 @@ Capybara = {
} else if(type == "checkbox" || type == "radio") {
node.checked = (value == "true");
this.trigger(index, "click");
+ this.trigger(index, "change");
} else {
node.value = value;
}

4 comments on commit 465e5ed

@fxposter

Well, It's cool, but http://www.quirksmode.org/dom/events/change.html shows that IE's handling of change event on checkboxes is far from perfect...

@jferris
thoughtbot, inc. member

Are you saying that capybara-webkit's new behavior is incorrect?

@fxposter

It depends :) From the point of view of Firefox, for example, it is truly valid behavior. From IE's point of view - it is not. Personally I think it's the right thing :)

@jferris
thoughtbot, inc. member

Yeah, I think it makes sense to behave like Safari/Chrome as much as possible. We can't simulate other DOMs, etc, since we only have one implementation.

Please sign in to comment.