Skip to content

Instantly share code, notes, and snippets.

@luxzeitlos
Created April 26, 2016 14:06
Show Gist options
  • Save luxzeitlos/eb3c475bf97b96758c97057808fa1711 to your computer and use it in GitHub Desktop.
Save luxzeitlos/eb3c475bf97b96758c97057808fa1711 to your computer and use it in GitHub Desktop.
checked event on input
import Ember from 'ember';
export default Ember.Controller.extend({
boxes:[{id:1},{id:2},{id:3}],
boxArr: Ember.computed('[email protected]', {
get() {
let disableOthers = Ember.get(this, 'boxes').filterBy('value', true).get('length') >= 2;
return Ember.get(this, 'boxes').map(({id, value}) => {
return {
id,
value,
disabled: disableOthers && !value,
};
});
}
}),
actions: {
disableCheckbox(id, event) {
Ember.set(Ember.get(this, 'boxes').findBy('id', id), 'value', event.target.checked);
}
}
});
<h1>boxes</h1>
<ul>
{{#each boxes as |box|}}
<li>{{box.id}}: {{box.value}}</li>
{{/each}}
</ul>
<h1>check</h1>
<ul>
{{#each boxArr as |box|}}
<li>
{{ input type="checkbox" disabled=box.disabled checked=box.value change=(action "disableCheckbox" box.id)}} {{checkbox.id}}
</li>
{{/each}}
</ul>
{
"version": "0.7.2",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"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.4.4/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.4.3/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.4/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment