Problem with jQuery & live('change') #57

ahawkins opened this Issue May 19, 2011 · 7 comments


None yet
6 participants

I have a form with a checkbox. Checking,unchecking the the box submits the form: Here's the JS:

  // make the finish todo form submit when the box is checked
  $('form.todo.finish input[type=checkbox]').live('change', function() {
    return true;

The turns out, that event handler is not executed with capybara-webkit, but it does pass in selenium.

Here's the step:

within "form#{dom_id(todo, :edit)}.todo.finish" do
  check 'todo_finished'

jferris commented May 23, 2011

I think we just need to manually trigger the event when a check box is checked. The place to do this would be spec/driver_spec.rb and src/capybara.js if you want to try your hand at a patch.

hgmnz commented Jul 29, 2011

Aren't we already triggering the change event here?

alduro commented Sep 20, 2011

It seems I have the same problem. Having these two lines in a @javascript tagged scenario:
And I select "BSAC" from "membership[to_party_id]"
And I select second option from "membership_membership_type_id"

The first select triggering the change event to make and Ajax call that populates the second dropdown but it never being populated so the second select failed.

When /^I select second option from "([^"])"$/ do |locator|
select(find(:xpath, "//
[@id='#{locator}']/option[2]").text, :from => "#{locator}")

coffescript that makes the Ajax call:

$ ->
$("#membership_to_party_id").change( () ->
, { org_id: @.value }
, (data) ->
$("select#membership_membership_type_id option").remove();
row = "<option value="" + "" + "">" + "-- Select --" + ""
$.each(data, (index, elem) ->
row = "<option value="" + data[index].id + "">" + data[index].short_description + ""


halogenandtoast commented Jan 27, 2012

I tested this out. The change event is triggering. @alduro I'm going to go on a limb here an say your issue is that your xpath expression is invalid. You've provided an axis, but no node. This seemed to work fine for me select(find(:xpath, "//select[@id='#{locator}']/option[2]").text, :from => "#{locator}")

I don't want to be out of line here, but I have a change event on a textfield that is not triggering when I fill_in some text in it. Is there another way to do it?


jferris commented Jun 6, 2012

@closedbracket you can manually trigger events using trigger:

find_field("Some Label").set("some text").trigger("change")

capybara-webkit does fire change events for textfields, though. Can you also try your scenario using the Selenium driver? If you're still having issues, please open a new issue, as the original issue here was related to a bad xpath expression.

@jferris Thank you. It was my bad for not including js: true. Silly mistake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment