Skip to content

Instantly share code, notes, and snippets.

@k-fish
Last active July 18, 2016 15:52
Show Gist options
  • Save k-fish/c1cc537b1f8f56ac4f32d79e1b9b8bae to your computer and use it in GitHub Desktop.
Save k-fish/c1cc537b1f8f56ac4f32d79e1b9b8bae to your computer and use it in GitHub Desktop.
Input wrapping approach custom formatting mut
import Ember from 'ember';
export default Ember.TextField.extend({});
import Ember from 'ember';
export default Ember.Component.extend({
formatValue: function(value) {
if (value) {
return value + '8';
}
},
actions: {
onkeyup(value) {
var value = this.formatValue(value);
this.set('value', value); //external
this.set('internalValue', value);
}
}
});
import Ember from 'ember';
export default Ember.TextField.extend({
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
foobar: 'Test String',
foobar2: 'Test 2',
formatter(value) {
return value + '8';
},
actions: {
changeMut(value) {
value = this.formatter(value);
this.set('foobar2', value);
}
}
});
<h1>Test</h1>
<br>
<br>
{{outlet}}
<h3>Wrapped input</h3>
{{input-wrapper-component value=foobar}}
{{foobar}}
<h3>Mut input</h3>
{{mut-input value=(readonly foobar2) key-up=(action 'changeMut')}}
{{foobar2}}
<br>
<br>
{{input-component value=internalValue key-up=(action 'onkeyup')}}
{
"version": "0.10.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.6.0",
"ember-data": "2.6.1",
"ember-template-compiler": "2.6.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment