Skip to content

Instantly share code, notes, and snippets.

@zeppelin
Created March 20, 2018 10:35
Show Gist options
  • Save zeppelin/fce2bf7dbdcc664be3668832d56ebef6 to your computer and use it in GitHub Desktop.
Save zeppelin/fce2bf7dbdcc664be3668832d56ebef6 to your computer and use it in GitHub Desktop.
cp-validations-default-value
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
import { validator, buildValidations } from 'ember-cp-validations';
const Validations = buildValidations({
email1: [
validator('format', {
type: 'email'
})
],
email2: [
validator('format', {
type: 'email'
})
]
});
export default Model.extend({
email1: attr({ defaultValue: 'hello' }),
email2: attr({ defaultValue: () => 'hello' })
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
let book = this.store.createRecord('book');
console.log(book.changedAttributes());
return book;
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
{
"version": "0.13.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "release",
"ember-template-compiler": "release",
"ember-testing": "release"
},
"addons": {
"ember-data": "2.16.3",
"ember-cp-validations": "*"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment