Last active
January 3, 2017 08:58
-
-
Save Thanood/975bb3889aaf8ba0622f5cd5affd61c6 to your computer and use it in GitHub Desktop.
Aurelia-Materialize bridge datepicker label
This file contains hidden or 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> | |
<require from="./md-datepicker-label"></require> | |
<require from="./stringifyValueConverter"></require> | |
<div> | |
Thanks to @MaximBalaganskiy! | |
</div> | |
<div> | |
<input md-datepicker-label="next appointment" md-datepicker="container: body; value.two-way: selectedDate;" type="date" /> | |
</div> | |
<div> | |
<button md-button click.delegate="setDate()">set date</button> | |
</div> | |
<div> | |
<span if.bind="selectedDate">You selected (UTC time): ${selectedDate | stringify}</span> | |
</div> | |
</template> |
This file contains hidden or 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 { | |
selectedDate = null; | |
setDate() { | |
let date = new Date(); | |
this.selectedDate = date; | |
} | |
} |
This file contains hidden or 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> | |
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
</head> | |
<body aurelia-app="main"> | |
<h1>Loading...</h1> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.6/system.js"></script> | |
<script src="https://rawgit.com/aurelia-ui-toolkits/aurelia-materialize-bundles/0.20.2/config2.js"></script> | |
<script> | |
System.import('aurelia-bootstrapper'); | |
</script> | |
</body> | |
</html> |
This file contains hidden or 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
/******************************************************************************* | |
* The following two lines enable async/await without using babel's | |
* "runtime" transformer. Uncomment the lines if you intend to use async/await. | |
* | |
* More info here: https://github.com/jdanyow/aurelia-plunker/issues/2 | |
*/ | |
//import regeneratorRuntime from 'babel-runtime/regenerator'; | |
//window.regeneratorRuntime = regeneratorRuntime; | |
/******************************************************************************/ | |
import 'materialize'; | |
export function configure(aurelia) { | |
aurelia.use | |
.standardConfiguration() | |
.developmentLogging() | |
.plugin('aurelia-materialize-bridge', bridge => bridge.useAll() ); | |
aurelia.start().then(a => a.setRoot()); | |
} |
This file contains hidden or 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
import {inject} from "aurelia-framework"; | |
@inject(Element) | |
export class MdDatepickerLabelCustomAttribute { | |
constructor(element) { | |
this.element = element; | |
} | |
value; | |
attached() { | |
var input = $(this.element); | |
var div = $("<div class='input-field date-picker'></div>"); | |
var va = this.element.attributes.getNamedItem("validate"); | |
if (va) | |
div.attr(va.name, va.value); | |
input.wrap(div); | |
var label = $(`<label class='${input.val() ? "active" : ""}' for='${this.element.id}'>${this.value}</label>`).insertAfter(input); | |
var picker = $(this.element).pickadate('picker'); | |
picker.on("close", () => { | |
if (input.val()) | |
label.addClass("active"); | |
else | |
label.removeClass("active"); | |
}); | |
} | |
} |
This file contains hidden or 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 StringifyValueConverter { | |
toView(value) { | |
if (value) { | |
return JSON.stringify(value); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment