Created
March 16, 2017 16:55
-
-
Save benshine/d958edb4e49acac0928b63a6e2bc7936 to your computer and use it in GitHub Desktop.
emberx-form: git diff -w v0.0.1 v0.0.4 -- addon/
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
diff --git a/addon/components/x-form.js b/addon/components/x-form.js | |
index 6b1627a..4a5a727 100644 | |
--- a/addon/components/x-form.js | |
+++ b/addon/components/x-form.js | |
@@ -1,8 +1,10 @@ | |
import Ember from 'ember'; | |
+import Changeset from 'ember-changeset'; | |
+import lookupValidator from 'ember-changeset-validations'; | |
import applyChangeset from '../utils/apply-changeset'; | |
-import layout from '../templates/components/x-field'; | |
+import layout from '../templates/components/x-form'; | |
-const { get, set, RSVP } = Ember; | |
+const { computed, get, set, RSVP } = Ember; | |
/** | |
@@ -65,7 +67,24 @@ export default Ember.Component.extend({ | |
* @property onCancel - Action for cancel/close behavior | |
* @type {Function} | |
*/ | |
- cancel: Ember.K, | |
+ onCancel: Ember.K, | |
+ | |
+ init() { | |
+ this._super(...arguments); | |
+ if(!this.get('data')) { | |
+ throw new Error('x-form needs data'); | |
+ } | |
+ }, | |
+ | |
+ changeset: computed('data', 'validations', function() { | |
+ let validations = this.get('validations') ? this.get('validations') : {}; | |
+ | |
+ return new Changeset( | |
+ this.get('data'), | |
+ lookupValidator(validations), | |
+ validations | |
+ ); | |
+ }), | |
actions: { | |
/** | |
@@ -105,6 +124,7 @@ export default Ember.Component.extend({ | |
} | |
}) | |
.finally(() => { | |
+ set(this, 'validations', Object.assign({}, get(this, 'validations'))); | |
set(this, 'isSubmitting', false); | |
}); | |
}, | |
diff --git a/addon/templates/components/x-form.hbs b/addon/templates/components/x-form.hbs | |
index e8148a6..b9f1734 100644 | |
--- a/addon/templates/components/x-form.hbs | |
+++ b/addon/templates/components/x-form.hbs | |
@@ -1,4 +1,3 @@ | |
-{{#with (changeset data validations) as |changeset|}} | |
{{yield | |
(hash | |
changeset=changeset | |
@@ -15,4 +14,3 @@ | |
) | |
) | |
}} | |
-{{/with}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment