Last active
September 19, 2017 06:35
-
-
Save 3gwebtrain/5fbc32a2dfe4e7678903f0180ed97766 to your computer and use it in GitHub Desktop.
component validation from route
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.Component.extend({ | |
message: 'error message goes here', | |
}); |
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', | |
name:'techM', | |
error:"error is here", | |
errorMessages:{ | |
error1:"error1" | |
}, | |
}); |
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 Validations from '../validation' | |
export default Ember.Route.extend(Validations, { | |
model(){ | |
return {num:null, errorMessage:"error" } | |
}, | |
actions:{ | |
validate(){ | |
var that = this; | |
this.validate().then(({model, validations})=>{ | |
if(model.get('validations.attrs.controller.model.num.isValid')){ | |
console.log('statge', validations.get('isValid') ); | |
this.controllerFor(this.routeName).set('model.errorMessage', ''); | |
}else{ | |
if(model.get('validations.attrs.controller.model.num.isInvalid')){ | |
console.log('statge', validations.get('isValid') ); | |
var errorMessage = model.get('validations.attrs.controller.model.num.message'); | |
this.controllerFor(this.routeName).set('model.errorMessage', errorMessage ) | |
} | |
} | |
}) | |
} | |
} | |
}); |
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-cp-validations":"3.4.0" | |
} | |
} |
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 { validator, buildValidations } from 'ember-cp-validations'; | |
export default buildValidations({ | |
'controller.model.num': [ | |
validator('number',{ | |
allowString: true, | |
integer: true, | |
message: 'Error! This is not an integer!' | |
}), | |
validator('presence', true) | |
] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment