Skip to content

Commit

Permalink
Add a way to provide component with a data object separate from schema
Browse files Browse the repository at this point in the history
add lodash to jshint globals
  • Loading branch information
toddjordan committed Jan 14, 2016
1 parent 42d54bd commit 5b669bf
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 5 deletions.
9 changes: 6 additions & 3 deletions addon/components/dynamic-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ const DynamicForm = Ember.Component.extend({
} else {
schemaObj = schema;
}
if (this.attrs.postRender) {
const postRenderFn = this.attrs.postRender.value;
schemaObj["postRender"] = postRenderFn;
if (this.get('postRender')) {
const postRenderFn = this.get('postRender');
schemaObj.postRender = postRenderFn;
}
if (this.get('data')) {
schemaObj.data = this.get('data');
}
return schemaObj;
},
Expand Down
3 changes: 2 additions & 1 deletion tests/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"andThen",
"currentURL",
"currentPath",
"currentRouteName"
"currentRouteName",
"_"
],
"node": false,
"browser": false,
Expand Down
47 changes: 47 additions & 0 deletions tests/integration/components/data-binding-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//import Ember from 'ember';
import hbs from 'htmlbars-inline-precompile';
import { moduleForComponent, test } from 'ember-qunit';

const schemaObject = {
"schema": {
"title": "What do you think of Alpaca?",
"type": "object",
"properties": {
"name": {
"type": "string",
"title": "Name"
},
"ranking": {
"type": "string",
"title": "Ranking",
"enum": ['excellent', 'not too shabby', 'alpaca built my hotrod']
}
}
}
};

const dataObject = {
"name": "Todd Jordan",
"ranking": "not too shabby"
};

moduleForComponent('/dynamic-form' , 'Integration | Component | dynamic-form:data-binding', {
integration: true
});

test('should update input value when model updated', function (assert) {
const fixtureSchema = _.clone(schemaObject, true);
const done = assert.async();
fixtureSchema.postRender = () => {
assert.equal(this.$('.alpaca-field-text input').val(), 'Todd Jordan');
dataObject.name = 'Jeremy Rowe';
fixtureSchema.postRender = () => {
assert.equal(this.$('.alpaca-field-text input').val(), 'Jeremy Rowe');
done();
};
this.render(hbs`{{dynamic-form schema=schemaObject data=dataObject}}`);
};
this.set('schemaObject', fixtureSchema);
this.set('dataObject', dataObject);
this.render(hbs`{{dynamic-form schema=schemaObject data=dataObject}}`);
});
1 change: 0 additions & 1 deletion tests/integration/components/dynamic-form-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Ember from 'ember';
import hbs from 'htmlbars-inline-precompile';
import { moduleForComponent, test } from 'ember-qunit';

Expand Down

0 comments on commit 5b669bf

Please sign in to comment.