Last active
July 18, 2017 12:03
-
-
Save olenderhub/a1981c0341d858ef9dda8f477ec2ff65 to your computer and use it in GitHub Desktop.
New Twiddle
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 Ember from 'ember'; | |
| import MyModelValidations from 'app/validations/my-model'; | |
| import lookupValidator from 'ember-changeset-validations'; | |
| import Changeset from 'ember-changeset'; | |
| const { get, inject, set } = Ember; | |
| export default Ember.Component.extend({ | |
| store: inject.service(), | |
| actions: { | |
| update(object, propertyName, value) { | |
| console.log(get(object, 'errors')); | |
| set(object, propertyName, value); | |
| console.log(get(object, 'errors')); | |
| }, | |
| register(changeset) { | |
| debugger | |
| changeset.validate().then(() => { | |
| debugger | |
| changeset | |
| return true | |
| }); | |
| } | |
| }, | |
| init() { | |
| this._super(...arguments); | |
| let model = get(this, 'store').createRecord('my-model'); | |
| const changeset = new Changeset(model, lookupValidator(MyModelValidations), MyModelValidations); | |
| set(this, 'changeset', changeset); | |
| }, | |
| }); |
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 Ember from 'ember'; | |
| export default Ember.Controller.extend({ | |
| appName: 'Ember Twiddle' | |
| }); |
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 Model from "ember-data/model"; | |
| import attr from "ember-data/attr"; | |
| import { belongsTo, hasMany } from "ember-data/relationships"; | |
| export default Model.extend({ | |
| firstName: attr('string'), | |
| lastName: attr('string') | |
| }); |
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
| { | |
| "version": "0.12.1", | |
| "EmberENV": { | |
| "FEATURES": {} | |
| }, | |
| "options": { | |
| "use_pods": false, | |
| "enable-testing": false | |
| }, | |
| "dependencies": { | |
| "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
| "ember": "2.12.0", | |
| "ember-template-compiler": "2.12.0", | |
| "ember-testing": "2.12.0" | |
| }, | |
| "addons": { | |
| "ember-data": "2.12.1", | |
| "ember-changeset": "1.2.1", | |
| "ember-changeset-validations": "1.2.4", | |
| "ember-form-for": "2.0.0-alpha.15", | |
| "ember-i18n": "5.0.2" | |
| } | |
| } |
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 { validatePresence, validateNumber } from 'ember-changeset-validations/validators'; | |
| import validateCustom from '../validators/custom'; | |
| export default { | |
| firstName: [ | |
| validatePresence({ presence: true }), | |
| validateCustom() | |
| ], | |
| lastName: [ | |
| validatePresence({ presence: true }) | |
| ] | |
| } |
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 default function validateCustom({ min, max } = {}) { | |
| return (key, newValue, oldValue, changes, content) => { | |
| // validation logic | |
| return 'error' | |
| // return `true` if valid || error message string if invalid | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment