Skip to content

Instantly share code, notes, and snippets.

@3cp
Forked from jdanyow/app.html
Last active October 2, 2018 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save 3cp/55559f3bd606aa854502f3ddbbcad480 to your computer and use it in GitHub Desktop.
Save 3cp/55559f3bd606aa854502f3ddbbcad480 to your computer and use it in GitHub Desktop.
input date
<template>
<input type="date" value.bind="value | momentDate">
<p>Value: ${value}</p>
</template>
export class App {
value = moment();
}
// chrome does not display the value in this format,
// chrome displays "03/10/2018",
// but internally the value is "2018-10-03".
// This is indeed confusing.
const domDateFormat = 'YYYY-MM-DD';
export class MomentDateValueConverter {
toView(value) {
let valueAsMoment;
if (!moment.isMoment(value)) {
valueAsMoment = moment(value);
} else {
valueAsMoment = value;
}
// when feeding the DOM, there is no choice on format
return valueAsMoment.format(domDateFormat);
}
fromView(value) {
return moment(value, domDateFormat);
}
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body aurelia-app>
<h1>Loading...</h1>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/jspm_packages/system.js"></script>
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/config.js"></script>
<script>
System.import('aurelia-bootstrapper');
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment