See => https://stackoverflow.com/questions/48968988/extend-aurelia-validation-rules-on-a-per-class-basis
Last active
November 10, 2018 22:09
-
-
Save bryandh/70c228b475d83d0926004c04a390cb9f to your computer and use it in GitHub Desktop.
Aurelia Validation rule extending
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> | |
valid? => ${valid} | |
</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 * as x from 'aurelia-dependency-injection'; | |
import { Product } from './product'; | |
import * as av from 'aurelia-validation'; | |
// import { ValidationController } from 'aurelia-validation'; | |
console.log('x', x); | |
console.log('av', av); | |
// @inject(NewInstance.of(ValidationController)) | |
export class App | |
{ | |
constructor(controller) | |
{ | |
console.log('controller', controller); | |
// console.log('ValidationRules', ValidationRules); | |
const product = new Product(); | |
product.name = 'test product' | |
console.log('product', product); | |
} | |
} |
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> | |
<meta name="viewport" content="width=device-width, initial-scale=1" /> | |
<script defer src="https://use.fontawesome.com/releases/v5.0.6/js/all.js"></script> | |
</head> | |
<body aurelia-app="main"> | |
Loading... | |
<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 src="https://cdn.rawgit.com/aurelia/validation/383490df/dist/amd/aurelia-validation.js"></script>--> | |
<!--<script src="https://cdn.rawgit.com/aurelia/validation/383490df/dist/commonjs/aurelia-validation.js"></script>--> | |
<!--<script src="https://cdn.rawgit.com/aurelia/validation/383490df/dist/es2015/aurelia-validation.js"></script>--> | |
<!--<script src="https://cdn.rawgit.com/aurelia/validation/383490df/dist/es2017/aurelia-validation.js"></script>--> | |
<!--<script src="https://cdn.rawgit.com/aurelia/validation/383490df/dist/native-modules/aurelia-validation.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
export function configure(aurelia) { | |
console.log('aurelia configure', aurelia); | |
aurelia.use | |
.standardConfiguration() | |
.plugin('aurelia-validation'); | |
aurelia.start().then(() => aurelia.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 { ValidationRules } from "aurelia-validation"; | |
// import * as av from 'aurelia-validation'; | |
export class Product { | |
name; | |
price; | |
} | |
ValidationRules | |
.ensure('name').required() | |
.ensure('price').required() | |
.on(Product); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment