I want to create dirty flag functionality using knockout. I want to enable the save button only if something has changed. My view and my view model is exactly same as exampl
There is also the ko.editables plugin: https://github.com/romanych/ko.editables
var user = {
FirstName: ko.observable('Some'),
LastName: ko.observable('Person'),
Address: {
Country: ko.observable('USA'),
City: ko.observable('Washington')
}
};
ko.editable(user);
user.beginEdit();
user.FirstName('MyName');
user.hasChanges(); // returns `true`
user.commit();
user.hasChanges(); // returns `false`
user.Address.Country('Ukraine');
user.hasChanges(); // returns `true`
user.rollback();
user.Address.Country(); // returns 'USA'