Skip to content

Instantly share code, notes, and snippets.

@superlou
Last active July 20, 2019 00:54
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 superlou/84bcf8bb6586cf270c998fa7187c63d4 to your computer and use it in GitHub Desktop.
Save superlou/84bcf8bb6586cf270c998fa7187c63d4 to your computer and use it in GitHub Desktop.
<input value={{value}} oninput={{action (mut this.newValue) value="target.value"}}/>
{{#if isChanged}}
<button {{action "reset"}}>reset</button>
{{/if}}
import Component from '@ember/component';
import { computed } from '@ember/object';
import { oneWay } from '@ember/object/computed';
export default Component.extend({
classNameBindings: ['isChanged'],
isChanged: computed('value', 'newValue', function() {
if (this.newValue) {
return this.value != this.newValue;
} else {
return false;
}
}),
actions: {
reset() {
console.log('here');
console.log(this.get('value'));
this.set('newValue', this.get('value'));
}
}
});
<h1>{{model.title}}</h1>
<p>Title: <EditableText @value={{model.title}} @newValue={{mut title}}/></p>
<p>Application number: <EditableText @value={{model.number}} @newValue={{mut number}}/></p>
<p>Publication number: <EditableText @value={{model.publication}} @newValue={{mut publication}}/></p>
<button {{action "save"}}>Save</button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment