Skip to content

Commit

Permalink
Safari desktop does not have a date input widget
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeis committed Apr 10, 2013
1 parent 724dba4 commit ae05234
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 3 additions & 1 deletion javascript/atoms/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ bot.action.type = function(
}

// mobile safari (iPhone / iPad). one cannot 'type' in a date field
if (goog.userAgent.WEBKIT && element.type == 'date') {
// chrome implements this, but desktop Safari doesn't, what's webkit again?
if ((!(goog.userAgent.product.SAFARI && !goog.userAgent.MOBILE)) &&
goog.userAgent.WEBKIT && element.type == 'date') {
var val = goog.isArray(values)? values = values.join("") : values;
var datePattern = /\d{4}-\d{2}-\d{2}/;
if (val.match(datePattern)) {
Expand Down
11 changes: 8 additions & 3 deletions javascript/atoms/test/type_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,11 @@
});
}

function browserImplementsDateInputWidget() {
// chrome and mobile safari
return goog.userAgent.WEBKIT && !(goog.userAgent.product.SAFARI && !goog.userAgent.MOBILE);
}

function testTypeDate() {
var dateInput = document.getElementById("date");
dateInput.value = "";
Expand All @@ -484,17 +489,17 @@
var dateInput = document.getElementById("date");
dateInput.value = "";
bot.action.type(dateInput, "2013-01-01T12:10:12.000Z");
assertEquals(dateInput.value, goog.userAgent.WEBKIT ? "2013-01-01" : "2013-01-01T12:10:12.000Z");
assertEquals(dateInput.value, browserImplementsDateInputWidget() ? "2013-01-01" : "2013-01-01T12:10:12.000Z");
dateInput.value = "";
}
function testTypeInvalidDate() {
var dateInput = document.getElementById("date");
dateInput.value = "";
bot.action.type(dateInput, "2013-13-01");
assertEquals(dateInput.value, goog.userAgent.WEBKIT ? "" : "2013-13-01");
assertEquals(dateInput.value, browserImplementsDateInputWidget() ? "" : "2013-13-01");
dateInput.value = "";
bot.action.type(dateInput, "February 28, 2013");
assertEquals(dateInput.value, goog.userAgent.WEBKIT ? "" : "February 28, 2013");
assertEquals(dateInput.value, browserImplementsDateInputWidget() ? "" : "February 28, 2013");
}
</script>
</head>
Expand Down

0 comments on commit ae05234

Please sign in to comment.