Skip to content

Instantly share code, notes, and snippets.

@GCheung55
Forked from czosel/controllers.application.js
Created January 20, 2021 01:22
Show Gist options
  • Save GCheung55/38c9739a32bf15aea1b5beaf73295f8b to your computer and use it in GitHub Desktop.
Save GCheung55/38c9739a32bf15aea1b5beaf73295f8b to your computer and use it in GitHub Desktop.
ember-validated-form
import Ember from 'ember';
import UserValidations from 'twiddle/validations/user';
export default Ember.Controller.extend({
UserValidations,
actions: {
submit(model) {
console.log('submit', model)
model.save()
}
}
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return Ember.RSVP.hash({
user: {
firstName: 'Test',
}
});
}
});
{{#validated-form
model=(changeset model.user UserValidations)
on-submit = (action "submit")
submit-label = 'Save' as |f|}}
{{f.input label="First name" name="firstName"}}
{{f.input label="Last name" name="lastName"}}
{{f.input label="Age" name="age"}}
{{f.submit label="Save"}}
{{/validated-form}}
{
"version": "0.15.0",
"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.2.2",
"ember-template-compiler": "3.2.2",
"ember-testing": "3.2.2"
},
"addons": {
"ember-data": "3.2.0",
"ember-validated-form": "1.4.0"
}
}
import {
validatePresence,
validateLength,
validateNumber,
} from 'ember-changeset-validations/validators';
export default {
firstName: [validatePresence(true), validateLength({ min: 3, max: 40 })],
lastName: [validatePresence(true), validateLength({ min: 3, max: 40 })],
age: [validatePresence(true), validateNumber({gte:21})]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment