Skip to content

Instantly share code, notes, and snippets.

@samselikoff
Last active June 21, 2017 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samselikoff/50a438fc1a9fbb38a54b0b760ea8878f to your computer and use it in GitHub Desktop.
Save samselikoff/50a438fc1a9fbb38a54b0b760ea8878f to your computer and use it in GitHub Desktop.
capture checkbox
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
something: false,
i: 0,
actions: {
toggleSomething(e) {
e.preventDefault();
this.incrementProperty('i');
if (this.get('i') > 2) {
this.toggleProperty('something');
return true;
}
}
}
});
<h1>Welcome to {{appName}}</h1>
<p>I'm trying to capture a checkbox's click event, do some work, then update a property that's bound to the checkbox's checked property.</p>
<p>Note that the checkbox you click on doesn't behave as expected.</p>
<hr />
<label>
{{input type='checkbox' checked=something click=(action 'toggleSomething')}}
I'm using the helper
</label>
<label>
<input type='checkbox' checked={{something}} onclick={{action 'toggleSomething'}}>
I'm using an input
</label>
<p>Something will start toggling when <code>i</code> is 3</p>
<p>i is {{i}}</p>
<p>Something is {{something}}</p>
{{input type='checkbox' checked=something}}
{
"version": "0.12.1",
"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.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
},
"addons": {
"ember-data": "2.12.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment