Skip to content

MobileCRM.UI.EntityForm.onSave

rescocrm edited this page May 15, 2023 · 9 revisions

Binds or unbinds the handler for onSave event on EntityForm.

Arguments

Argument Type Description
handler function(entityForm) The handler function that has to be bound or unbound.
bind Boolean Determines whether to bind or unbind the handler.
scope Object The scope for handler calls.

This example demonstrates how to set an "onSave" handler to perform a validation before saving edited value on entity form. It will cancel the validation and sets the error message if the address is incomplete.

MobileCRM.UI.EntityForm.onSave(function (entityForm) {
	var addressDetail = entityForm.getDetailView("Address");
	var addrItem = addressDetail.getItemByName("address1_line1");
	if (!addrItem.value || addrItem.value.length == 0) {
		// Set the error message on detail item
		addrItem.errorMessage = "Street 1 line is empty.";
		// select second tab (zero-based)
		entityForm.form.selectedViewIndex = 1;
		entityForm.context.errorMessage = addrItem.errorMessage;
		// Return true to apply changed values
		return true;
	}
	// Return false to ignore all changes
	return false;
}, true, null);
Clone this wiki locally