ACE editor isDirty

HI all,
I would like to implement the isDirty function in the ace.js script in order to check if text is updated to not lose changed when closing. How to do it?
Thanks

Hello @codejoin ,

An ace-editor should work properly with e.g. Webix form’s isDirty given that it has a name provided: Code Snippet . You can see here that with an “” or “js string” as an initial value the function works fine.
When form elements are collected, the form saves the initial value of each its control. Then when calling isDirty(), the saved value is compared to the view’s current value, got via its getValue() method. Default comparison is a simple loose inequality operator (!=).

If form.isDirty() is not working as expected for you, make sure that an initial value is provided in the expected format of the ace.getValue() ( by default, our ace.js works in a “javascript” mode and editor.getValue() returns a js string ).

Or, if you would like an isDirty() method for the editor itself, you could use the same logic of saving the default value and comparing it in the method afterwards: Code Snippet .

Thanks so much for your reply.
However, for anyone interested in a workaround, this is my solution:

  1. setDirty(false)
    When I set the editor with content for the first time:
    $$(“x_ace_config_editor”).setValue(v);
    $$(“x_ace_config_editor”).getEditor().session.getUndoManager().markClean();

  2. isDirty()
    To check if it has been modified:
    if (!$$(“x_ace_config_editor”).getEditor().session.getUndoManager().isClean()) {}

1 Like