Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Input Caret Position (single)
import Ember from 'ember';
export default Ember.Component.extend({
edited: false,
actions: {
setText(text) {
this.set('edited', true);
let message = this.get('message');
message = Ember.copy(message);
message.text = text;
this.attrs.updateMessage(message);
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
init() {
this._super(...arguments);
this.set('model', { text: 'Lorem' });
},
title: Ember.computed('model.text', function() {
return this.get('model.text');
}),
actions: {
updateMessage(message) {
this.set('model', message);
}
}
});
<h1>{{title}}</h1>
{{my-component message=model updateMessage=(action "updateMessage")}}
<input value={{message.text}} oninput={{action "setText" value="target.value"}}>
<span>Edited: {{edited}}</span>
{
"version": "0.8.0",
"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.5.1",
"ember-data": "2.5.2",
"ember-template-compiler": "2.5.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.