Skip to content

Instantly share code, notes, and snippets.

@kumkanillam
Last active August 21, 2016 19:20
Show Gist options
  • Save kumkanillam/879003a723f0fab14d1fcbf8f0836d29 to your computer and use it in GitHub Desktop.
Save kumkanillam/879003a723f0fab14d1fcbf8f0836d29 to your computer and use it in GitHub Desktop.
import Ember from 'ember';
const {get,set} = Ember;
export default Ember.Component.extend({
val:'',
actions:{
update(newVal){
let oldVal = get(this, 'val');
console.log('newVal-',newVal+' oldVal-',oldVal);
if(!newVal.includes('C')) {
set(this, 'val', newVal);
} else {
this.$('#fieldId').val(oldVal);
}
}
}
});
import Ember from 'ember';
const {get,set} = Ember;
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
val:'',
actions:{
update(newVal){
let oldVal = get(this, 'val');
console.log('newVal-',newVal+' oldVal-',oldVal);
set(this, 'val', newVal);
if(newVal.includes('C')) {
Ember.run.schedule('afterRender', () => {
this.set('val', oldVal);
});
}
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
{{my-component }}
<br>
{{outlet}}
<br>
<br>
<input id='fieldId' name='fieldName' value={{val}} oninput={{action 'update' value='target.value'}} />
{{val}}
{{yield}}
{
"version": "0.10.4",
"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.7.0",
"ember-data": "2.7.0",
"ember-template-compiler": "2.7.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment