toddjordan / ember-cli-dynamic-forms

An Ember addon for creating dynamic forms
http://toddjordan.github.io/ember-cli-dynamic-forms/
MIT License
35 stars 16 forks source link

"[object Object]" for NULL values on display view #38

Closed PeterMead closed 8 years ago

PeterMead commented 8 years ago

When using a display view such as "bootstrap-display-horizontal" all NULL values are shown as "[object Object]" (without quotes).

This is caused by the _replaceKeywordsWithFunctions function confusing NULL values with objects. Specifically, line 128 of addon\components\dynamic-form.js where typeof value === 'object' equates to TRUE if value is NULL.

toddjordan commented 8 years ago

Thanks for reporting! will look at it today or tomorrow

toddjordan commented 8 years ago

Hey @PeterMead could you give me an example schema with null values for a recreate? The way I understand views is you just specify a string as the view.

PeterMead commented 8 years ago

Here's a minimal example. While I could pass in an array of strings as the data it would be nice if a model can be passed into a display view the same as it can for an edit view.


app/models/person.js

import DS from 'ember-data';

export default DS.Model.extend({
    firstName: DS.attr(),
    middleName: DS.attr(),
    lastName: DS.attr()
});

app/routes/person.js

import Ember from 'ember';

export default Ember.Route.extend({
    model(params) {
        let john = store.createRecord('person', {
            firstName: 'John',
            middleName: null,
            lastName: 'Doe'
        });

        let schema = {
            "schema": {
                "type": "object",
                "properties": {
                    "firstName": {
                        "type": "string",
                    },
                    "middleName": {
                        "type": "string",
                    },
                    "lastName": {
                        "type": "string",
                    }
                }
            },
            "options": {
                "fields": {
                    "firstName": {
                        "label": "First Name"
                    },
                    "middleName": {
                        "label": "Middle Name"
                    },
                    "lastName": {
                        "label": "Last Name"
                    }
                }
            },
            "view": "bootstrap-display-horizontal"
        };

        return Ember.RSVP.hash({
            schema: schema,
            data: john
        });
    }
});

app/templates/person.hbs

{{dynamic-form schema=model.schema data=model.data}}
toddjordan commented 8 years ago

Put in a fix and cut a release (v0.1.2)