Skip to content

Commit

Permalink
Fix for issue #38
Browse files Browse the repository at this point in the history
  • Loading branch information
toddjordan committed Aug 6, 2016
1 parent 24f2c65 commit 44cfdc0
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
2 changes: 2 additions & 0 deletions addon/components/dynamic-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ const DynamicForm = Ember.Component.extend({
if (typeObj) {
object[key] = typeObj[type.functionName];
} // else fail with a message that the given type couldn't be found
} else if (value === null) {
object[key] = '';
} else if (typeof value === 'object') {
object[key] = _.transform(value, replaceWithFunction);
} else {
Expand Down
2 changes: 1 addition & 1 deletion addon/renderers/alpaca.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ export default Ember.Object.extend({
render(schema, element) {
element.alpaca(schema);
}
})
});
52 changes: 52 additions & 0 deletions tests/integration/components/null-data-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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"
},
"feedback": {
"type": "string",
"title": "Feedback"
},
"ranking": {
"type": "string",
"title": "Ranking",
"enum": ['excellent', 'not too shabby', 'alpaca built my hotrod']
}
}
},
"view": "bootstrap-display-horizontal"
};


const dataObject = {
"name": "Todd Jordan",
"ranking": null,
"feedback": null
};

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

test('should render empty string for null value in display mode', function (assert) {
let fixtureSchema = _.clone(schemaObject, true);
let done = assert.async();
fixtureSchema.postRender = () => {
assert.equal(this.$('.alpaca-control[name="name"]').text(), "Todd Jordan");
assert.equal(this.$('.alpaca-control[name="feedback"]').text(), "");
assert.equal(this.$('.alpaca-control[name="ranking"]').text().trim(), "");
done();
};
this.set('schemaObject', fixtureSchema);
this.set('dataObject', dataObject);
this.render(hbs`{{dynamic-form schema=schemaObject data=dataObject}}`);


});

0 comments on commit 44cfdc0

Please sign in to comment.