Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix logic for maxlength attribute on input nodes and add tests.

Closes #131
  • Loading branch information...
commit 9c02a2046101045e1eb51634e2982b9d8c5b74db 1 parent 3b025e7
Joshua Clayton joshuaclayton authored
Showing with 27 additions and 1 deletion.
  1. +19 −0 spec/driver_spec.rb
  2. +8 −1 src/capybara.js
19 spec/driver_spec.rb
View
@@ -267,6 +267,7 @@
<html><body>
<form action="/" method="GET">
<input type="text" name="foo" value="bar"/>
+ <input type="text" name="maxlength_foo" value="bar" maxlength="10"/>
<input type="text" id="disabled_input" disabled="disabled"/>
<input type="checkbox" name="checkedbox" value="1" checked="checked"/>
<input type="checkbox" name="uncheckedbox" value="2"/>
@@ -312,6 +313,24 @@
input.value.should == "newvalue"
end
+ it "sets an input's value greater than the max length" do
+ input = subject.find("//input[@name='maxlength_foo']").first
+ input.set("allegories (poems)")
+ input.value.should == "allegories"
+ end
+
+ it "sets an input's value equal to the max length" do
+ input = subject.find("//input[@name='maxlength_foo']").first
+ input.set("allegories")
+ input.value.should == "allegories"
+ end
+
+ it "sets an input's value less than the max length" do
+ input = subject.find("//input[@name='maxlength_foo']").first
+ input.set("poems")
+ input.value.should == "poems"
+ end
+
it "sets an input's nil value" do
input = subject.find("//input").first
input.set(nil)
9 src/capybara.js
View
@@ -105,7 +105,14 @@ Capybara = {
if (type == "text" || type == "textarea" || type == "password") {
this.trigger(index, "focus");
node.value = "";
- var length = this.attribute(index, "maxlength") || value.length;
+ var maxLength = this.attribute(index, "maxlength"),
+ length;
+ if (maxLength && value.length > maxLength) {
+ length = maxLength;
+ } else {
+ length = value.length;
+ }
+
for(var strindex = 0; strindex < length; strindex++) {
node.value += value[strindex];
this.trigger(index, "keydown");
Please sign in to comment.
Something went wrong with that request. Please try again.