-
-
Save 3cp/55559f3bd606aa854502f3ddbbcad480 to your computer and use it in GitHub Desktop.
input date
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<input type="date" value.bind="value | momentDate"> | |
<p>Value: ${value}</p> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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