Skip to content

Commit

Permalink
ignore timestamp part of date (or any extra cruft sent)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeis authored and detro committed Mar 19, 2013
1 parent e529a9c commit 6790a0b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 3 additions & 2 deletions javascript/atoms/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,15 @@ 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/)) {
var datePattern = /\d{4}-\d{2}-\d{2}/;
if (val.match(datePattern)) {
// 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;
element.value = val.match(datePattern)[0];
bot.events.fire(element, bot.events.EventType.CHANGE);
bot.events.fire(element, bot.events.EventType.BLUR);
return;
Expand Down
15 changes: 15 additions & 0 deletions javascript/atoms/test/type_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,21 @@
var dateInput = document.getElementById("date");
bot.action.type(dateInput, "2013-01-01");
assertEquals(dateInput.value, "2013-01-01");
dateInput.value = "";
}
function testTypeDateWithTimestamp() {
var dateInput = document.getElementById("date");
bot.action.type(dateInput, "2013-01-01T12:10:12.000Z");
assertEquals(dateInput.value, "2013-01-01");
dateInput.value = "";
}
function testTypeInvalidDate() {
var dateInput = document.getElementById("date");
dateInput.value = "";
bot.action.type(dateInput, "2013-13-01");
assertEquals(dateInput.value, "");
bot.action.type(dateInput, "February 28, 2013");
assertEquals(dateInput.value, "");
}
</script>
</head>
Expand Down

0 comments on commit 6790a0b

Please sign in to comment.