I am using knockout-postbox to mark dirty flag. The code looks like this:
var ProfileModel = function() {
this.nickName = ko.observable("name1").publishOn("dirty", true);
this.emailAddress = ko.observable("email1").publishOn("dirty", true);
};
ko.postbox.subscribe("dirty", function(newValue) {
// enable Save button
}, this);
nickName and emailAddress are tied to input boxes.
<div id="profile">
<input data-bind="value: nickName" /> </label>
<input data-bind="value: emailAddress" /></label>
</div>
Steps to recreate the problem:
- User goes to nickName input box and delete the content.
dirty
is raised and Save button is enabled. - User clicks Save button. The change is saved and the Save button becomes disabled.
- User goes to emailAddress and delete the content.
dirty
is NOT raised somehow. User cannot save the change. - User types something on emailAddress or nickName.
dirty
is raised and Save button is enabled.
You can check out jsfiddle to see it in action. There is no Save button in the jsfiddle example, but just try deleting the content of nickName and then emailAddress. You will see deleting the emailAddress does not raise dirty
event.
Is this known bug in knockout-postbox? Is there better way to check dirtyness in knockout?