Skip to content

Commit

Permalink
handle sending keys to a date input element
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeis committed Mar 8, 2013
1 parent 66a54be commit bc59c1a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
17 changes: 17 additions & 0 deletions javascript/atoms/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,23 @@ bot.action.type = function(
}
}

// mobile safari (iPhone / iPad). one cannot 'type' in a date field
if (goog.userAgent.WEBKIT && element.type == 'date') {
var val = goog.isArray(values)? values = values.join("") : values;
if (val.match(/\d\d\d\d-\d\d-\d\d/)) {
// The following events get fired on iOS first
if (goog.userAgent.MOBILE && goog.userAgent.product.SAFARI) {
bot.events.fire(element, bot.events.EventType.TOUCHSTART);
bot.events.fire(element, bot.events.EventType.TOUCHEND);
}
bot.events.fire(element, bot.events.EventType.FOCUS);
element.value = val;
bot.events.fire(element, bot.events.EventType.CHANGE);
bot.events.fire(element, bot.events.EventType.BLUR);
return;
}
}

if (goog.isArray(values)) {
goog.array.forEach(values, typeValue);
} else {
Expand Down
7 changes: 7 additions & 0 deletions javascript/atoms/test/type_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,12 @@
assertFalse(keyboard.isPressed(SHIFT));
});
}

function testTypeDate() {
var dateInput = document.getElementById("date");
bot.action.type(dateInput, "2013-01-01");
assertEquals(dateInput.value, "2013-01-01");
}
</script>
</head>
<body>
Expand All @@ -482,6 +488,7 @@
<input type="password" id="password"/>
<input type="email" id="email"/>
<input type="search" id="search"/>
<input type="date" id="date"/>
<textarea id="textarea"></textarea>
<input type="text" id="inputCount"/>
<input type="text" id="textInputCount"/>
Expand Down

0 comments on commit bc59c1a

Please sign in to comment.