Skip to content
This repository has been archived by the owner on Dec 16, 2023. It is now read-only.

Commit

Permalink
Fix firing the change event on SELECT tags when using jQuery.
Browse files Browse the repository at this point in the history
  • Loading branch information
djanowski committed Jan 28, 2011
1 parent 719fd7d commit 42f9edd
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
42 changes: 42 additions & 0 deletions spec/js-libs-compat.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require "./helpers"
{ vows: vows, assert: assert, zombie: zombie, brains: brains } = require("vows")
jsdom = require("jsdom")

brains.get "/jquery", (req, res)-> res.send """
<html>
<head>
<title>jQuery</title>
<script src="/jquery.js"></script>
</head>
<body>
<select>
<option>None</option>
<option value="1">One</option>
</select>
<span id="option"></span>
</body>
<script>
$(function() {
$("select").bind("change", function() {
$("#option").text(this.value);
});
});
</script>
</html>
"""

vows.describe("Compatibility with JavaScript libraries").addBatch(
"jQuery":
zombie.wants "http://localhost:3003/jquery"
"selecting an option in a select element":
topic: (browser)->
browser.select "select", "1"
@callback null, browser
"should fire the change event": (browser)-> assert.equal browser.text("#option"), "1"


).export(module)
2 changes: 2 additions & 0 deletions src/zombie/browser.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,9 @@ class Browser extends require("events").EventEmitter
this.selectOption = (option)->
if(option && !option.selected)
select = @xpath("./ancestor::select", option).value[0]
@fire "beforeactivate", select
option.selected = true
@fire "beforedeactivate", select
@fire "change", select
return this

Expand Down

2 comments on commit 42f9edd

@bacey
Copy link

@bacey bacey commented on 42f9edd Mar 19, 2011

Choose a reason for hiding this comment

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

Hi!

You might not remember it, because it was a long time ago, but actually, when you committed this, you asked me to help with writing tests for the other input types. Well, at that time I didn't have the time for that (learning coffeescript, writing mini-servers in node for serving up the tests, etc.), and yes, I was selfish, because all I needed that my code works (ie. the select element correctly fires the change), long story short, I didn't write those tests.
Neither did now.
Because I still haven't got the time.
Sorry for that.

But I can confirm, that the other input elements (but at least the "input type=text") also need it. Now I'm using zombie 0.9.4 with jquery 1.4.x and I had to edit (yes, by hand) the .npm/zombie/active/package/lib/zombie/browser.js file, line 321, in the "fill" function. The same change as above is enough, ie:

    this.fire("beforeactivate", field);
    field.value = value;
    this.fire("beforedeactivate", field);
    this.fire("change", field);

Sorry for being lazy and not committing back to the project. I promise when I have time, I'll do that first!
Cheers,
Bela

@assaf
Copy link
Owner

@assaf assaf commented on 42f9edd Mar 22, 2011

Choose a reason for hiding this comment

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

It needs a test case, code without tests gets lost (often the most silly edit mistake), breaking unexpectedly.

Please sign in to comment.