Skip to content

Instantly share code, notes, and snippets.

@k-fish
Last active September 30, 2016 18:04
Show Gist options
  • Save k-fish/e681d14f3dbcd011e01fc7388eec13da to your computer and use it in GitHub Desktop.
Save k-fish/e681d14f3dbcd011e01fc7388eec13da to your computer and use it in GitHub Desktop.
Input change example
import Ember from 'ember';
export default Ember.Component.extend({
});
import Ember from 'ember';
export default Ember.Component.extend({
didReceiveAttrs({ newAttrs: { value }}) {
if (value) {
const v = value.value || value;
this.set('_internalValue', v);
}
},
modifyInput(value) {
return 15;
},
_internalValue: Ember.computed('value', {
get(key) {
return this.get('value');
},
set(key, value) {
return this.get('value');
}
}),
actions: {
inputChanged({ target }) {
let value = target.value;
console.log(value);
value = this.modifyInput(value);
this.attrs.inputChanged(value);
target.value = value;
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{container-component}}
<br>
<br>
Container value: {{value}}
{{input-component
value=(readonly value)
inputChanged=(action (mut value))
}}
Input value: {{value}}
<br/>
Input internal value: {{_internalValue}}
<br/>
<input value={{_internalValue}} oninput={{action 'inputChanged'}}>
{
"version": "0.10.5",
"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.8.0",
"ember-data": "2.8.0",
"ember-template-compiler": "2.8.0",
"ember-testing": "2.8.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment