How to check the dirty-state of an object.

I want the regular save-button on a form to differ from color depending on the state of the form’s object: Starting with grey because no change has yet been made to the object, going to green once one of the object’s attributes has been changed by the user; grey again once those changes are committed to the database. So depending on the dirty-state of the object. From In Mendix 7, the server object state has been moved to the client, which means that the server is now completely stateless and can be scaled horizontally at will. ... Because this statelessness, it is the client that keeps track of the objects that are not yet committed, objects that are not persistable, and even changes to the objects that were not committed yet. This makes me expect that it should be possible to sort this client-side without the databaseside-attribute IsDirty. But how can this be achieved?
3 answers

If you’d want to do this purely in Mendix, you could add an 'IsChanged’ boolean attribute to your entity, and add a onchange nano/microflow to every input on your form that sets this attribute to true (perhaps this widget can help:, and with conditional visibility disable/enable your button.  You could reset the attribute to false in a beforeCommit, so the button becomes disabled again when comitted to the db.

Haven't done it myself, but this is what I would try.

But perhaps it's easier to resort to some custom javascript..


The equivalent client-side function to isDirty is:


There are a few ways to go about implementing this. One option would be a nanoflow timer widget that calls a nanoflow, that calls a JavaScript action with code that checks hasChanges() and changes CSS classes on your button accordingly.

Since JS actions are still beta in 7.23, you could also use a JS snippet on the page that uses setInterval() and checks the value of hasChanges() on that interval.


The most standard implementation would be: set an on change microfllow on each editable attribute. In the microflow, check to see if anything has changed. You could check the AuditTrail module for a Java action that does this for you. The Mendix API has a method to check this as well: getChangedMembers() of IMendixObject. Set a custom boolean to flag whether something was changed or not. Use conditional visibility on two differently styled save buttons on your page.


I'm not familiar with Nanoflows, so you could check to see if there are options there.