Last active
January 12, 2019 00:08
-
-
Save jelhan/dc989bc6bf5dc2360e04b700a7cf3986 to your computer and use it in GitHub Desktop.
ember-bootstrap always show validation on edit forms
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({ | |
tagName: '', | |
}); |
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 UserValidations from '../validations/user'; | |
import { inject as controller } from '@ember/controller'; | |
import { readOnly } from '@ember/object/computed'; | |
import { assign } from '@ember/polyfills'; | |
export default Ember.Controller.extend({ | |
UserValidations, | |
indexController: controller('index'), | |
users: readOnly('indexController.users'), | |
actions: { | |
save(changeset) { | |
let nextId = this.users | |
.reduce((nextId, user) => nextId > user.id ? nextId : user.id + 1, 0); | |
let record = assign({ id: nextId }, changeset.get('change')); | |
this.users.push(record); | |
this.transitionToRoute('index'); | |
} | |
} | |
}); |
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 UserValidations from '../validations/user'; | |
export default Ember.Controller.extend({ | |
UserValidations, | |
actions: { | |
save(changeset) { | |
changeset.execute(); | |
console.log(changeset.get('data')); | |
this.transitionToRoute('index'); | |
} | |
} | |
}); |
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({ | |
users: [ | |
{ | |
id: '1', | |
firstName: 'John', | |
lastName: 'Doe', | |
email: '[email protected]', | |
}, | |
{ | |
id: '2', | |
firstName: 'Jane', | |
lastName: 'Doe', | |
email: '[email protected]', | |
}, | |
{ | |
id: '3', | |
firstName: 'Max', | |
lastName: 'Mustermann', | |
email: '[email protected]', | |
}, | |
], | |
}); |
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 EmberRouter from '@ember/routing/router'; | |
import config from './config/environment'; | |
const Router = EmberRouter.extend({ | |
location: 'none', | |
rootURL: config.rootURL | |
}); | |
Router.map(function() { | |
this.route('add'); | |
this.route('edit', { path: 'edit/:id' }); | |
}); | |
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'; | |
export default Ember.Route.extend({ | |
model() { | |
return | |
}, | |
}); |
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.15.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.4.3", | |
"ember-template-compiler": "3.4.3", | |
"ember-testing": "3.4.3" | |
}, | |
"addons": { | |
"ember-array-helper": "5.0.0", | |
"ember-bootstrap": "2.4.0", | |
"ember-bootstrap-changeset-validations": "1.0.0", | |
"ember-changeset-validations": "1.3.3", | |
"ember-router-helpers": "0.2.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 { validatePresence, validateFormat } from 'ember-changeset-validations/validators'; | |
export default { | |
firstName: validatePresence(true), | |
lastName: validatePresence(true), | |
email: validateFormat({ type: 'email' }) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment