Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Commit

Permalink
Trigger change event on checkbox and radio button when checked state …
Browse files Browse the repository at this point in the history
…is changed
  • Loading branch information
Vasily Reys authored and jferris committed Jun 14, 2011
1 parent d7f491d commit 465e5ed
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions spec/driver_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -467,12 +467,12 @@


it "triggers radio input events" do it "triggers radio input events" do
subject.find("//input[@type='radio']").first.set(true) 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 end


it "triggers checkbox events" do it "triggers checkbox events" do
subject.find("//input[@type='checkbox']").first.set(true) 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
end end


Expand Down
1 change: 1 addition & 0 deletions src/capybara.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Capybara = {
} else if(type == "checkbox" || type == "radio") { } else if(type == "checkbox" || type == "radio") {
node.checked = (value == "true"); node.checked = (value == "true");
this.trigger(index, "click"); this.trigger(index, "click");
this.trigger(index, "change");
} else { } else {
node.value = value; node.value = value;
} }
Expand Down

4 comments on commit 465e5ed

@fxposter
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@fxposter
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.