Created
December 19, 2016 14:08
-
-
Save Thanood/0857ed09491c1e551fcf68cb49723574 to your computer and use it in GitHub Desktop.
Aurelia-Materialize bridge datepicker validation + icon
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
| /* add this css to prevent the icon from appearing below the datepicker input */ | |
| .date-picker + i.material-icons { | |
| margin-left: -24px; | |
| line-height: 1; | |
| margin-top: 12px; | |
| cursor: pointer; | |
| } |
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="./app.css"></require> | |
| <md-card md-title="Basic"> | |
| <div> | |
| <input md-datepicker="options.bind: options; container: body; value.two-way: date & validate:rules;" md-datepicker.ref="datePicker" type="date" placeholder="pick a date"> | |
| </div> | |
| <div style="margin-top: 15px;"> | |
| <button md-waves md-button click.delegate="validateModel()">validate</button> | |
| <button md-waves md-button click.delegate="reset()">reset</button> | |
| </div> | |
| </md-card> | |
| <md-card if.bind="controller.errors.length"> | |
| <h5 class="error-text">You have errors!</h5> | |
| <ul style="margin-top: 15px;"> | |
| <li repeat.for="error of controller.errors"> | |
| <a href="#" click.delegate="openErrorTarget(error, $event)"> | |
| ${error.message} | |
| </a> | |
| </li> | |
| </ul> | |
| </md-card> | |
| </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
| import { inject, NewInstance } from 'aurelia-framework'; | |
| import { ValidationController, ValidationRules } from 'aurelia-validation'; | |
| import { MaterializeFormValidationRenderer } from 'aurelia-materialize-bridge'; | |
| @inject(NewInstance.of(ValidationController)) | |
| export class App { | |
| date = null; | |
| showErrortext = false; | |
| options = { | |
| showIcon: true | |
| }; | |
| controller = null; | |
| rules = ValidationRules | |
| .ensure('date') | |
| .displayName('Date') | |
| .required() | |
| .on(this) | |
| .rules; | |
| constructor(controller: ValidationController) { | |
| this.controller = controller; | |
| this.controller.addRenderer(new MaterializeFormValidationRenderer()); | |
| } | |
| reset() { | |
| this.date = null; | |
| this.controller.reset({ object: this, propertyName: 'date' }); | |
| } | |
| validateModel() { | |
| return this.controller.validate({ object: this, propertyName: 'date' }); | |
| } | |
| openErrorTarget(error, $event) { | |
| this[`${error.propertyName}Picker`].openDatePicker(); | |
| $event.preventDefault(); | |
| } | |
| } |
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.6/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() ) | |
| .plugin('aurelia-validation'); | |
| aurelia.start().then(a => a.setRoot()); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment