Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rwjblue/b54b452dd12ea98a7f0952d2ab9014bb to your computer and use it in GitHub Desktop.
Save rwjblue/b54b452dd12ea98a7f0952d2ab9014bb to your computer and use it in GitHub Desktop.

Revisions

  1. rwjblue revised this gist Apr 23, 2019. 2 changed files with 9 additions and 2 deletions.
    7 changes: 7 additions & 0 deletions helpers.eq.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    import Ember from 'ember';

    export function eq(params/*, hash*/) {
    return params;
    }

    export default Ember.Helper.helper(eq);
    4 changes: 2 additions & 2 deletions templates.components.select-component.hbs
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@

    <select value={{value}} onchange={{action onChange}}>
    <select onchange={{action onChange}}>
    {{#each options as |opt|}}
    <option value={{opt.key}}>{{opt.label}}</option>
    <option value={{opt.key}} selected={{eq opt.key value}}>{{opt.label}}</option>
    {{/each}}
    </select>

  2. @alias-mac alias-mac revised this gist Apr 16, 2019. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion templates.components.select-component.hbs
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,8 @@
    Value: {{value}}

    <select value={{value}} onchange={{action onChange}}>
    {{#each options as |opt|}}
    <option value={{opt.key}}>{{opt.label}}</option>
    {{/each}}
    </select>

    Value: {{value}}
  3. @alias-mac alias-mac revised this gist Apr 16, 2019. No changes.
  4. @alias-mac alias-mac revised this gist Apr 16, 2019. No changes.
  5. @alias-mac alias-mac revised this gist Apr 16, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions templates.components.checkbox-component.hbs
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,9 @@
    {{checked}}

    <input type="checkbox"
    name="state"
    id={{label}}
    checked={{checked}}
    onchange={{action changeState}}
    />
    <label for="active">Label for {{checked}}</label>
    <label for="active">{{checked}}</label>

  6. @alias-mac alias-mac revised this gist Apr 16, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion templates.components.checkbox-component.hbs
    Original file line number Diff line number Diff line change
    @@ -5,5 +5,5 @@
    checked={{checked}}
    onchange={{action changeState}}
    />
    <label for="active">Active</label>
    <label for="active">Label for {{checked}}</label>

  7. @alias-mac alias-mac revised this gist Apr 16, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions templates.application.hbs
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,10 @@
    <h1>Welcome to {{appName}}</h1>
    <br>
    <br>
    <h3>Checkbox value should be in sync</h3>
    {{#each data key="checked" as |state|}}
    {{checkbox-component label=state.label checked=state.checked changeState=(action "changeState")}}
    {{/each}}

    <h2>Select doesn't keep value</h2>
    <h3>Select value should be in sync</h3>

    {{select-component value=selected options=options onChange=(action "changeSelectValue")}}
  8. @alias-mac alias-mac revised this gist Apr 16, 2019. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion templates.application.hbs
    Original file line number Diff line number Diff line change
    @@ -5,5 +5,6 @@
    {{checkbox-component label=state.label checked=state.checked changeState=(action "changeState")}}
    {{/each}}

    {{selected}}
    <h2>Select doesn't keep value</h2>

    {{select-component value=selected options=options onChange=(action "changeSelectValue")}}
  9. @alias-mac alias-mac revised this gist Apr 16, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion templates.components.select-component.hbs
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    Value: {{value}}
    <select value={{value}} onchange={{action onChange}}>
    {{#each options as |opt|}}
    <option key={{opt.key}}>{{opt.label}}</option>
    <option value={{opt.key}}>{{opt.label}}</option>
    {{/each}}
    </select>
  10. @alias-mac alias-mac revised this gist Apr 16, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion templates.application.hbs
    Original file line number Diff line number Diff line change
    @@ -5,5 +5,5 @@
    {{checkbox-component label=state.label checked=state.checked changeState=(action "changeState")}}
    {{/each}}


    {{selected}}
    {{select-component value=selected options=options onChange=(action "changeSelectValue")}}
  11. @alias-mac alias-mac revised this gist Apr 16, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion templates.components.select-component.hbs
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    {{value}}
    Value: {{value}}
    <select value={{value}} onchange={{action onChange}}>
    {{#each options as |opt|}}
    <option key={{opt.key}}>{{opt.label}}</option>
  12. @alias-mac alias-mac revised this gist Apr 16, 2019. No changes.
  13. @alias-mac alias-mac revised this gist Apr 16, 2019. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions templates.components.select-component.hbs
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    {{value}}
    <select value={{value}} onchange={{action onChange}}>
    {{#each options as |opt|}}
    <option key={{opt.key}}>{{opt.label}}</option>
  14. @alias-mac alias-mac revised this gist Apr 16, 2019. No changes.
  15. @alias-mac alias-mac revised this gist Apr 16, 2019. 2 changed files with 2 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion controllers.application.js
    Original file line number Diff line number Diff line change
    @@ -41,7 +41,7 @@ export default Ember.Controller.extend({
    this.set('data', newData);
    },

    changeCheckbox() {
    changeSelectValue() {

    this.set('selected', 'option3');
    }
    2 changes: 1 addition & 1 deletion templates.application.hbs
    Original file line number Diff line number Diff line change
    @@ -6,4 +6,4 @@
    {{/each}}


    {{select-component value=selected options=options}}
    {{select-component value=selected options=options onChange=(action "changeSelectValue")}}
  16. @alias-mac alias-mac revised this gist Apr 16, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions templates.components.select-component.hbs
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    <select value={{value}}>
    <select value={{value}} onchange={{action onChange}}>
    {{#each options as |opt|}}
    <option key={{opt.key}}>{{opt.label}}</option>
    {{/each}}
    </select>
    </select>
  17. @alias-mac alias-mac revised this gist Apr 16, 2019. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions controllers.application.js
    Original file line number Diff line number Diff line change
    @@ -39,6 +39,11 @@ export default Ember.Controller.extend({
    });

    this.set('data', newData);
    },

    changeCheckbox() {

    this.set('selected', 'option3');
    }
    }
    });
  18. @alias-mac alias-mac revised this gist Apr 16, 2019. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions controllers.application.js
    Original file line number Diff line number Diff line change
    @@ -23,6 +23,10 @@ export default Ember.Controller.extend({
    label: 'Option 2',
    key: 'option2',
    },
    {
    label: 'Option 3',
    key: 'option3',
    },
    ],

    actions: {
  19. @alias-mac alias-mac revised this gist Apr 16, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion templates.components.select-component.hbs
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    <select>
    <select value={{value}}>
    {{#each options as |opt|}}
    <option key={{opt.key}}>{{opt.label}}</option>
    {{/each}}
  20. @alias-mac alias-mac revised this gist Apr 16, 2019. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions controllers.application.js
    Original file line number Diff line number Diff line change
    @@ -25,8 +25,6 @@ export default Ember.Controller.extend({
    },
    ],

    selected: 'option1',

    actions: {
    changeState() {
    const newData = this.get('data').map((d) => {
  21. @alias-mac alias-mac revised this gist Apr 16, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions templates.components.select-component.hbs
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    <select>
    {{#each options as |option|}}
    <option key={{option.key}}>{{option.label}}</option>
    {{#each options as |opt|}}
    <option key={{opt.key}}>{{opt.label}}</option>
    {{/each}}
    </select>
  22. @alias-mac alias-mac revised this gist Apr 16, 2019. 3 changed files with 4 additions and 1 deletion.
    2 changes: 2 additions & 0 deletions controllers.application.js
    Original file line number Diff line number Diff line change
    @@ -25,6 +25,8 @@ export default Ember.Controller.extend({
    },
    ],

    selected: 'option1',

    actions: {
    changeState() {
    const newData = this.get('data').map((d) => {
    1 change: 1 addition & 0 deletions templates.application.hbs
    Original file line number Diff line number Diff line change
    @@ -6,3 +6,4 @@
    {{/each}}


    {{select-component value=selected options=options}}
    2 changes: 1 addition & 1 deletion templates.components.select-component.hbs
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    <select value={{value}}>
    <select>
    {{#each options as |option|}}
    <option key={{option.key}}>{{option.label}}</option>
    {{/each}}
  23. @alias-mac alias-mac revised this gist Apr 16, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion templates.application.hbs
    Original file line number Diff line number Diff line change
    @@ -5,4 +5,4 @@
    {{checkbox-component label=state.label checked=state.checked changeState=(action "changeState")}}
    {{/each}}

    {{select-component value=selected options=options}}

  24. @alias-mac alias-mac revised this gist Apr 16, 2019. 3 changed files with 17 additions and 3 deletions.
    11 changes: 11 additions & 0 deletions controllers.application.js
    Original file line number Diff line number Diff line change
    @@ -14,6 +14,17 @@ export default Ember.Controller.extend({
    }
    ],

    options: [
    {
    label: 'Option 1',
    key: 'option1',
    },
    {
    label: 'Option 2',
    key: 'option2',
    },
    ],

    actions: {
    changeState() {
    const newData = this.get('data').map((d) => {
    3 changes: 1 addition & 2 deletions templates.application.hbs
    Original file line number Diff line number Diff line change
    @@ -5,5 +5,4 @@
    {{checkbox-component label=state.label checked=state.checked changeState=(action "changeState")}}
    {{/each}}


    {{select-component value=selected options=options}}
    {{select-component value=selected options=options}}
    6 changes: 5 additions & 1 deletion templates.components.select-component.hbs
    Original file line number Diff line number Diff line change
    @@ -1 +1,5 @@
    {{yield}}
    <select value={{value}}>
    {{#each options as |option|}}
    <option key={{option.key}}>{{option.label}}</option>
    {{/each}}
    </select>
  25. @alias-mac alias-mac revised this gist Apr 16, 2019. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions templates.application.hbs
    Original file line number Diff line number Diff line change
    @@ -4,3 +4,6 @@
    {{#each data key="checked" as |state|}}
    {{checkbox-component label=state.label checked=state.checked changeState=(action "changeState")}}
    {{/each}}


    {{select-component value=selected options=options}}
  26. @alias-mac alias-mac revised this gist Apr 16, 2019. No changes.
  27. @alias-mac alias-mac revised this gist Apr 16, 2019. 2 changed files with 5 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions components.select-component.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    import Ember from 'ember';

    export default Ember.Component.extend({
    });
    1 change: 1 addition & 0 deletions templates.components.select-component.hbs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    {{yield}}
  28. @godserahul1986 godserahul1986 created this gist Apr 8, 2019.
    3 changes: 3 additions & 0 deletions components.checkbox-component.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    import Ember from 'ember';

    export default Ember.Component.extend({});
    29 changes: 29 additions & 0 deletions controllers.application.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    import Ember from 'ember';

    export default Ember.Controller.extend({
    appName: 'Ember Twiddle',

    data: [
    {
    checked: true,
    label: 'active'
    },
    {
    checked: false,
    label: 'archived'
    }
    ],

    actions: {
    changeState() {
    const newData = this.get('data').map((d) => {
    return {
    ...d,
    checked: true
    }
    });

    this.set('data', newData);
    }
    }
    });
    6 changes: 6 additions & 0 deletions templates.application.hbs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    <h1>Welcome to {{appName}}</h1>
    <br>
    <br>
    {{#each data key="checked" as |state|}}
    {{checkbox-component label=state.label checked=state.checked changeState=(action "changeState")}}
    {{/each}}
    9 changes: 9 additions & 0 deletions templates.components.checkbox-component.hbs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    {{checked}}
    <input type="checkbox"
    name="state"
    id={{label}}
    checked={{checked}}
    onchange={{action changeState}}
    />
    <label for="active">Active</label>

    19 changes: 19 additions & 0 deletions twiddle.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    {
    "version": "0.15.1",
    "EmberENV": {
    "FEATURES": {}
    },
    "options": {
    "use_pods": false,
    "enable-testing": false
    },
    "dependencies": {
    "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
    "ember": "3.4.3",
    "ember-template-compiler": "3.4.3",
    "ember-testing": "3.4.3"
    },
    "addons": {
    "ember-data": "3.4.2"
    }
    }