Skip to content

Instantly share code, notes, and snippets.

@feanor07
Created November 23, 2016 22:28
Show Gist options
  • Save feanor07/6646707a141a36240d1f24ff0d361b1a to your computer and use it in GitHub Desktop.
Save feanor07/6646707a141a36240d1f24ff0d361b1a to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none'
});
Router.map(function() {
this.route('farray');
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
properties: null,
datax: null,
init() {
this.properties = Ember.A();
this.properties.pushObject({name: 'name', level: 'advanced', type: 'text', title: 'My Name', value: '123'});
this.properties.pushObject({name: 'city', type: 'select', title: 'City', value: 'Brno', options: ['Brno', 'Praha', 'New York']});
this.properties.pushObject({name: 'author', level: 'advanced', type: 'text', title: 'Author', value: null, defaultValue: 'Hugo Hugo'});
},
model() {
this.datax = {};
this.properties.forEach((x) => {
this.datax[x.name] = x.value;
})
return {
xyz: this.datax,
properties: this.properties,
};
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
Go to the {{#link-to 'farray'}}demo{{/link-to}}.
{{outlet}}
<br>
<br>
Form
{{#form-for (changeset model.xyz) submit=(action onSubmit) as |f|}}
{{#each model.properties as |prop| }}
{{#fields-for prop as |fa|}}
{{#if (eq prop.type 'text')}}
{{f.text-field prop.name label=prop.title placeholder=prop.defaultValue hint='aaaa'}}
{{/if}}
{{#if (eq prop.type 'select')}}
{{f.select-field prop.name prop.options label=prop.title}}
{{/if}}
{{/fields-for}}
{{/each}}
{{f.submit "Create account"}}
{{/form-for}}
{
"version": "0.10.6",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.9.0",
"ember-data": "2.9.0",
"ember-template-compiler": "2.9.0",
"ember-testing": "2.9.0"
},
"addons": {
"ember-form-for": "2.0.0-alpha.13",
"ember-changeset": "1.2.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment