javascript - How to track changes in form object in aurelia to activate revert button -
we using aurelia crate single page application creating/editing employee details. in edit employee form, need give functionality revert local changes if any. trick disable button if there no local changes
i tried using computedfrom, observing properties , not complex object.
here sample code -
import {bindable, computedfrom} 'aurelia-framework' export class employee { @bindable employee @computedfrom('employee') enablerevert() { return true; } revert() { // revert functionality goes here } }
thanks help!
employee.html
<button disabled.bind="!haschanged()">revert</button>
employee.js
attached() { object.assign(this.originalemployee, employee); } haschanged() { // @favio said, iterate on original copy of employee object. (let p in employee) { if (employee[p] !== this.originalemployee[p]) { return true; } } return false; }
Comments
Post a Comment