Last active
January 7, 2020 16:24
-
-
Save 3gwebtrain/6ffa733456cbe4affe5d052c04bf5ab8 to your computer and use it in GitHub Desktop.
validation from Router
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 Ember from 'ember'; | |
import config from './config/environment'; | |
const Router = Ember.Router.extend({ | |
location: 'none', | |
rootURL: config.rootURL | |
}); | |
Router.map(function() { | |
this.route('my-route'); | |
}); | |
export default Router; |
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} | |
}, | |
actions:{ | |
check(){ | |
this.set('message',''); | |
this.validate().then(({model, validations})=>{ | |
if(model.get('validations.attrs.controller.model.num.isValid')){ | |
console.log('statge', validations.get('isValid') ) | |
}else{ | |
if(model.get('validations.attrs.controller.model.num.isInvalid')){ | |
console.log('statge', validations.get('isValid') ) | |
} | |
} | |
}) | |
} | |
} | |
}); |
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