RadDataForm: Commit

If you followed the getting started article, you now know how to edit an object's properties with DataForm for NativeScript. Now to get the result of these modifications, you need to commit the modifications to the object and get the result.

Commit Modes

You can choose when the commit of the changes happens by changing the data form's commitMode property. Here are the available commit modes:

  • Immediate - this is the default mode; all changes are committed immediately when the editor value is changed;
  • OnLostFocus - the changes are committed when another editor gets focused;
  • Manual - the changes are committed only when the commitAll method of data form is called;

Once the modifications are committed you can get them by using the editedObject property of the data form.

Commit Events

The data form provides propertyCommit and propertyCommitted events that you can use to get notified that some modifications are committed or are about to be.
The propertyCommit event notifies you before the actual commit so you can optionally cancel it by setting the returnValue of the arguments to false:

<RadDataForm [source]="person" marginTop="50" row="1" (groupExpanded)="dfGroupExpanded($event)" (groupCollapsed)="dfGroupCollapsed($event)"
    (propertyCommit)="dfPropertyCommit($event)" (propertyCommitted)="dfPropertyCommitted($event)">
public dfPropertyCommit(args) {
    if (args.propertyName == "name") {
        this._eventsText = "LastEvent: name property commit cancelled";
        args.returnValue = false;
    }
}

The other event - propertyCommitted - can be used to actually get the new value from the data form's editedObject property.

References

Want to see this scenario in action?
Check our SDK examples for Angular repo on GitHub. You will find this and many other practical examples with NativeScript UI.

Related articles you might find useful: