Skip to content

Instantly share code, notes, and snippets.

@ptgamr
Last active February 29, 2016 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ptgamr/1f8338dbb7163db90dba to your computer and use it in GitHub Desktop.
Save ptgamr/1f8338dbb7163db90dba to your computer and use it in GitHub Desktop.
{{input value=field.value key-press="updateValue"}}
{{#if isFieldDirty}}
Field is dirty
{{/if}}
import Ember from 'ember';
export default Ember.Component.extend({
field: null,
isFieldDirty: Ember.computed('field.value', {
get() {
return this.get('field.value') !== this.get('field.originalValue')
}
})
actions: {
updateValue(newValue) {
this.get('onFieldValueChange')(newValue);
}
}
});
{{#each fields as |field|}}
{{field-component field=field onFieldValueChange=(mut field.value)}}
{{/each}}
import Ember from 'ember';
export default Ember.Component.extend({
fields: Ember.computed({
get() {
return [
{name: 'id', value: 'id', originalValue: 'id'},
{name: 'username', value: 'username', originalValue: 'username'},
]
}
})
actions: {
reset() {
//reset all the fields to make value === originalValue
}
}
});
Raw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment