Skip to content

Instantly share code, notes, and snippets.

@patrickberkeley
Last active February 6, 2016 05:54
Show Gist options
  • Select an option

  • Save patrickberkeley/e44bcb878f3e793f4b8d to your computer and use it in GitHub Desktop.

Select an option

Save patrickberkeley/e44bcb878f3e793f4b8d to your computer and use it in GitHub Desktop.

Revisions

  1. patrickberkeley revised this gist Feb 6, 2016. 3 changed files with 4 additions and 8 deletions.
    9 changes: 3 additions & 6 deletions application.controller.js
    Original file line number Diff line number Diff line change
    @@ -6,14 +6,11 @@ const {
    } = Ember;

    export default Ember.Controller.extend({
    // singleVal: '',
    singleVal: '',
    actions:{
    addField() {
    // Unless `singleVal` really needs to be on the model, I'd recommend
    // just adding it as property on this controller. See the comment
    // above, and use it here with `get(this, 'singleVal')`.
    get(this, 'model.images').addObject(get(this, 'model.singleVal'));
    set(this, 'model.singleVal', '');
    get(this, 'model.images').addObject(get(this, 'singleVal'));
    set(this, 'singleVal', '');
    }
    }
    });
    1 change: 0 additions & 1 deletion application.route.js
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,6 @@ import Ember from 'ember';
    export default Ember.Route.extend({
    model:function(){
    return {
    singleVal: '',
    images: [ ]
    }
    }
    2 changes: 1 addition & 1 deletion application.template.hbs
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    {{input value=info}}<br/>
    {{/each}}

    image {{input value=model.singleVal}}
    image {{input value=singleVal}}

    <br/><br/>

  2. patrickberkeley revised this gist Feb 6, 2016. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions application.controller.js
    Original file line number Diff line number Diff line change
    @@ -6,8 +6,12 @@ const {
    } = Ember;

    export default Ember.Controller.extend({
    // singleVal: '',
    actions:{
    addField() {
    // Unless `singleVal` really needs to be on the model, I'd recommend
    // just adding it as property on this controller. See the comment
    // above, and use it here with `get(this, 'singleVal')`.
    get(this, 'model.images').addObject(get(this, 'model.singleVal'));
    set(this, 'model.singleVal', '');
    }
  3. patrickberkeley created this gist Feb 6, 2016.
    15 changes: 15 additions & 0 deletions application.controller.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    import Ember from 'ember';

    const {
    get,
    set
    } = Ember;

    export default Ember.Controller.extend({
    actions:{
    addField() {
    get(this, 'model.images').addObject(get(this, 'model.singleVal'));
    set(this, 'model.singleVal', '');
    }
    }
    });
    10 changes: 10 additions & 0 deletions application.route.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    import Ember from 'ember';

    export default Ember.Route.extend({
    model:function(){
    return {
    singleVal: '',
    images: [ ]
    }
    }
    });
    12 changes: 12 additions & 0 deletions application.template.hbs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    {{#each model.images as |info|}}
    <label>image:</label>
    {{input value=info}}<br/>
    {{/each}}

    image {{input value=model.singleVal}}

    <br/><br/>

    <button {{action "addField"}}>
    ADD INPUT FIELD
    </button>
    15 changes: 15 additions & 0 deletions twiddle.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    {
    "version": "0.5.0",
    "EmberENV": {
    "FEATURES": {}
    },
    "options": {
    "enable-testing": false
    },
    "dependencies": {
    "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
    "ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember.debug.js",
    "ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.2.0/ember-data.js",
    "ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember-template-compiler.js"
    }
    }