Last active
May 1, 2020 23:33
-
-
Save visoft/0d0a0f211c818a5300b4deaac7e159d6 to your computer and use it in GitHub Desktop.
Bootstrap Changeset Form
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 Controller from '@ember/controller'; | |
import { tracked } from '@glimmer/tracking'; | |
import { Changeset } from 'ember-changeset'; | |
import { action } from '@ember/object'; | |
import FormValidator from '../validators/form'; | |
import lookupValidator from 'ember-changeset-validations'; | |
export default class ApplicationController extends Controller { | |
@tracked formModel = { name: null, foo: null }; | |
constructor() { | |
super(...arguments); | |
this.changeset = Changeset(this.formModel, lookupValidator(FormValidator), FormValidator); | |
} | |
@action | |
async saveForm(changeset) { | |
await changeset.validate(); | |
} | |
} |
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.17.0", | |
"EmberENV": { | |
"FEATURES": {}, | |
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": true, | |
"_APPLICATION_TEMPLATE_WRAPPER": false, | |
"_JQUERY_INTEGRATION": false | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"ember": "3.17.0", | |
"ember-template-compiler": "3.17.0", | |
"ember-testing": "3.17.0" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.0", | |
"ember-bootstrap": "3.1.3", | |
"ember-bootstrap-changeset-validations": "3.0.0", | |
"ember-changeset": "3.3.1", | |
"ember-changeset-validations": "3.3.1" | |
} | |
} |
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, validateLength } from 'ember-changeset-validations/validators'; | |
export default { | |
name: [validatePresence(true), validateLength({ min: 4 })], | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment