Last active
March 12, 2020 03:03
-
-
Save jelhan/01db3b47199b70d64fdbff3013cc696b to your computer and use it in GitHub Desktop.
ember-bootstrap-changeset-validations-upgrade-v3-bug
This file contains 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 Changeset from 'ember-changeset'; | |
import lookupValidator from 'ember-changeset-validations'; | |
import { validateLength } from 'ember-changeset-validations/validators'; | |
const Validations = { | |
name: validateLength({ min: 2 }), | |
}; | |
export default Ember.Component.extend({ | |
init() { | |
this._super(...arguments); | |
this.model = new Changeset({ name: 'f' }, lookupValidator(Validations), Validations); | |
this.property = 'name'; | |
}, | |
setupValidations() { | |
let key = `model.error.${this.get('property')}.validation`; | |
defineProperty(this, 'errors', computed(`${key}[]`, function() { | |
return A(this.get(key)); | |
})); | |
}, | |
validate() { | |
let m = this.model; | |
assert('Model must be a Changeset instance', m && typeof m.validate === 'function'); | |
return new RSVP.Promise( function(resolve, reject) { | |
m.validate().then( | |
() => { | |
model.get('isValid') ? resolve() : reject(); | |
}, | |
reject | |
); | |
}); | |
}, | |
actions: { | |
validate() { | |
this.validate(); | |
} | |
}, | |
}); |
This file contains 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 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.16.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.14.3", | |
"ember-template-compiler": "3.14.3", | |
"ember-testing": "3.14.3" | |
}, | |
"addons": { | |
"ember-changeset": "3.0.6", | |
"ember-changeset-validations": "3.0.2", | |
"ember-data": "3.14.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment