Problem discarding modification in navigation editor

Hello,
I’m developing a button bar for browsing the records in an editor.
I was inspired by an example found online reported by Konstantin Krivopustov ( navigator-editor sample).
I have reconstructed an example with the problem I am experiencing and a small video where you can see the behavior.

Basically, by using more than one datasource inside the editor (for example in the case of embedded entity) in case of modification and subsequent discard by navigation to another item, I can’t clean up the isModified flag after replacing the current editor item and this mark any next record as to be commited.
To explain myself better I made a video showing the problem.

Obviously the example is simplified, in my final code I am creating an abstraction and obviously I would like to find a solution that does not depend on the number of datasources connected to the main editor.
Thanks for the help!
Fabrizio

sample.zip (6.8 MB)

Hi Fabrizio,

You can make all datasources of the current screen unmodified with the following code:

public void changeCurrentItem(Customer itemToReplace) {
    Customer reloadedItemToReplace = dataSupplier.reload(itemToReplace, customersDs.getView());
    onReplaceItem(() -> {
        setItem(reloadedItemToReplace);
        for (Datasource datasource : getDsContext().getAll()) {
            ((DatasourceImplementation) datasource).setModified(false);
        }
    });
}

Regards,
Konstantin

Thank you so much Konstantin, it works perfectly!
Regards,
Fabrizio