Skip to content

Instantly share code, notes, and snippets.

@andrewtimberlake
Last active January 4, 2016 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andrewtimberlake/52dcb86774f26c0c2cdb to your computer and use it in GitHub Desktop.
Save andrewtimberlake/52dcb86774f26c0c2cdb to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle',
actions: {
handleAnswer(questionId, value) {
alert('answer handled ' + questionId + ' ' + value);
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{question-answer actionAnswer=(action "handleAnswer")}}
<br>
<br>
import Ember from 'ember';
export default Ember.Component.extend({
defaultLayout: null,
tagName: 'input',
type: 'radio',
attributeBindings: ['type', 'name', 'value', 'id', 'isChecked:checked', 'required', 'disabled'],
value: null,
answer: null,
checked: null,
id: Ember.computed('name', 'value', function () {
return this.get('name')+'-'+this.get('value');
}),
isChecked: Ember.computed('value', 'answer', function() {
return this.get('value') === parseInt(this.get('answer'));
}),
change: function() {
console.log('Component "input-radio": change');
Ember.run.once(this, 'sendChangedAction');
},
sendChangedAction() {
console.log('Component "input-radio": sendChange');
console.log('updateAnswer: '+this.get('checked'));
this.sendAction('changed', this.get('value'));
}
});
import Ember from 'ember';
export default Ember.Component.extend({
id: '',
question: null,
answer: null,
tagName: 'ul',
answers: [
{value: 1, label: 'Volledig'},
{value: 2, label: 'Grotendeels'},
{value: 3, label: 'Enigzins'},
{value: 4, label: 'Niet'},
],
results: [],
click: function (ev) {
console.log('Component "question-answer" action: answer', ev);
console.log(this.get('value'));
this.sendAction('actionAnswer', this.get('question.id'), this.get('value'));
},
inputName: Ember.computed('value', function() {
return 'question-'+this.get('question.id');
})
});
{{#each answers as |data|}}
<li>
{{input-radio value=data.value name=inputName answer=answer}}
<label for="question-{{question.id}}-{{data.value}}">
<span class="image"></span>
<span>{{data.label}}</span>
</label>
</li>
{{/each}}
{
"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"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment