Using The Commit Events

Developers can listen for commit operations either globally (for every editor) or locally (for a single editor). While listening for commit events, developers can cancel commit operations.

To listen for global commits RadDataForm exposes two methods. These are addCommitListener() and removeCommitListener(). The methods accept a single argument of type EntityPropertyCommitListener.

Here is a sample implementation of the interface:

@Override
public boolean onBeforeCommit(EntityProperty entityProperty) {
    // To cancel the commit for a given property return true.
    if(entityProperty.name().equals("Age")) {
        return true;
    }

    return false;
}

@Override
public void onAfterCommit(EntityProperty entityProperty) {
    // Do something after a property has been committed.
}
public class CommitListener : Java.Lang.Object, IEntityPropertyCommitListener
{
    public void OnAfterCommit (IEntityProperty p0)
    {

    }

    public bool OnBeforeCommit (IEntityProperty p0)
    {
        // Return true to cancel the commit for the given property.
        if (p0.Name ().Equals ("Age")) {
            return true;
        }

        return false;
    }
}

Then to use listener simply add it to the data form commit listeners:

// The commit listener will be notified before and after each property is committed.
// The global data form commit listeners are only notified when the CommitMode is set to Manual.
form.addCommitListener(this);
dataForm.BeforeCommit += (object sender, Com.Telerik.Widget.Dataform.Engine.BeforeCommitEventArgs e) => {
    e.Handled = true;
};

dataForm.AfterCommit += (object sender, Com.Telerik.Widget.Dataform.Engine.AfterCommitEventArgs e) => {
};

To listen for changes of a single property this code can be used:

// Add a commit listener for a specific property. This way the listener will be notified whenever a
// commit is attempted regardless of the data form commit mode.
form.getExistingEditorForProperty("Age").property().addCommitListener(this);
CommitListener commitListener = new CommitListener ();
dataForm.GetExistingEditorForProperty ("Age").Property().AddCommitListener(commitListener);