Skip to content

Commit

Permalink
Image submit now works.
Browse files Browse the repository at this point in the history
Signed-off-by: Assaf Arkin <assaf@labnotes.org>
  • Loading branch information
josevalim authored and assaf committed Jan 4, 2011
1 parent 550bb16 commit 2ec4fb6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
19 changes: 19 additions & 0 deletions spec/forms-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ brains.get "/form", (req, res)-> res.send """
<input type="unknown" name="unknown" value="yes">
<input type="reset" value="Reset">
<input type="submit" name="button" value="Submit">
<input type="image" name="image" id="image_submit" value="Image Submit">
<button name="button" value="hit-me">Hit Me</button>
</form>
Expand All @@ -58,6 +59,7 @@ brains.post "/submit", (req, res)-> res.send """
<div id="hobbies">#{JSON.stringify(req.body.hobbies)}</div>
<div id="unknown">#{req.body.unknown}</div>
<div id="clicked">#{req.body.button}</div>
<div id="image_clicked">#{req.body.image}</div>
</body>
</html>
"""
Expand Down Expand Up @@ -286,6 +288,23 @@ vows.describe("Forms").addBatch(
"should send input values to server": (browser)->
assert.equal browser.text("#name"), "ArmBiter"
assert.equal browser.text("#likes"), "Arm Biting"
"should not send other button values to server": (browser)->
assert.equal browser.text("#image_clicked"), "undefined"

"by clicking image button":
zombie.wants "http://localhost:3003/form"
topic: (browser)->
browser.fill("Name", "ArmBiter").fill("likes", "Arm Biting").
pressButton "#image_submit", @callback
"should open new page": (browser)-> assert.equal browser.location, "http://localhost:3003/submit"
"should add location to history": (browser)-> assert.length browser.window.history, 2
"should send image value to server": (browser)-> assert.equal browser.text("#image_clicked"), "Image Submit"
"should send input values to server": (browser)->
assert.equal browser.text("#name"), "ArmBiter"
assert.equal browser.text("#likes"), "Arm Biting"
"should not send other button values to server": (browser)->
assert.equal browser.text("#clicked"), "undefined"

"by clicking input":
zombie.wants "http://localhost:3003/form"
topic: (browser)->
Expand Down
5 changes: 3 additions & 2 deletions src/zombie/forms.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ core.HTMLFormElement.prototype.submit = (button)->
else if field.nodeName == "INPUT" && field.type == "file"
params[name] = new UploadedFile(field.value) if field.value
else if field.nodeName == "TEXTAREA" || field.nodeName == "INPUT"
params[name] = field.value if field.value
if field.value && field.type != "submit" && field.type != "image"
params[name] = field.value

process index + 1
else
Expand Down Expand Up @@ -93,7 +94,7 @@ core.HTMLInputElement.prototype._eventDefaults =
when "reset"
if form = input.form
form.reset()
when "submit"
when "submit", "image"
if form = input.form
form._dispatchSubmitEvent input
when "checkbox"
Expand Down

0 comments on commit 2ec4fb6

Please sign in to comment.