Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate forms on-the-fly using EmberJS and JSON schema?

I searched and found this question (GUI-based or Web-based JSON editor that works like property explorer) that has several links to resources that generate UI from JSON.

I am interested in any examples or known projects that show emberjs working with JSON Schema (http://json-schema.org/) to generate on-the-fly Forms. Projects such as:

  • Alpacajs(http://www.alpacajs.org)
  • json-editor(https://github.com/jdorn/json-editor)

Any Ideas?

like image 871
JScadden Avatar asked May 05 '14 23:05

JScadden


1 Answers

Yes you can trivially generate forms dynamically based on some JSON.

You will need to map your JSON object into an array of keys in your router (or controller):

model: function() {
  var json = {a: 'red', b: 'yellow', c: 'blue'};
  var items = [], key;
  for (key in json) {
    if (json.hasOwnProperty(key)) {
      items.push({name: key, value: json[key]});
    }
  }
  return items;
}

And just use the each helper in your view:

{{#each field in content}}
  {{field.name}}: {{input type="text" value=field.value}}<br>
{{/each}}

I made a working JSBin with the above code.

like image 162
Andrew Hacking Avatar answered Sep 22 '22 01:09

Andrew Hacking