sfSaveForm

Saves the current form.

Syntax

sfSaveForm(parameters, callback)

Parameters

Name

Type

Mandatory

Description

Name

Type

Mandatory

Description

parameters

json

yes

Parameters to customize the process of saving form e.g. skip showing the form status popup, force validation before saving etc.

See supported parameters.

callback

function

yes

Code block to be executed after the prerequisite steps to save the form has been completed and before sending the request to the server.

See callback function.

parameters

The parameters supported in the function are:

Name

Type

Mandatory

Description

Name

Type

Mandatory

Description

CustomSave

boolean

no

Set true to skip the form status popup where the user can change the status.

Set false to show the form status popup so the user can select a status to save the form in and continue.

If no value is passed, it is considered as false and the form status popup is shown.

If set to true, the form is saved in the current status itself. If the status has to be changed automatically, sfSetFormStatus can be used to set the form status before executing this function.

ValidateForm

boolean

no

Set true to validate mandatory fields before the form can be saved. If any of the mandatory field is empty, then a validation error message is shown to the user, the callback function is skipped and the form is not saved.

Set false to skip validation of mandatory fields and continue saving the form.

If no value is passed, it is considered as true and the mandatory fields are validated.

It is not recommended to skip validation of mandatory fields as it may result in inconsistent data and affect the further workflow of the form.

Redirect

boolean

no

Set true to redirect the user to the previous screen (that was open before the current form) after the current form is saved. Usually, it returns to the view from where the form was opened or in case of sub forms, it returns to the parent form.

Set false to stay on the current form after the form data is saved.

If no value is passed, it is considered as false and no redirection takes place.

ConfirmBeforeSave

boolean

no

Set true to show a confirmation dialog to the user and continue with save operation only when the user has confirmed. If the user cancels out of the dialog, no further action is done i.e. none of the steps like showing the form status popup, validation etc are executed.

Set false to continue without a confirmation dialog.

If no value is passed, it is considered as false and no confirmation dialog is shown.

The general format of the parameters json is:

{ "CustomSave": true/false, "ValidateForm": true/false, "Redirect": true/false, "ConfirmBeforeSave": true/false }

Usage examples

Example 1

Let us consider a form contains a button SkipAndContinue that allows an operator to save the form without requiring them to complete the rest of the form. When the user clicks on the button, the form should be saved in its current status and redirect back to the view.

sfRegisterFieldCallback('control_skipandcontinue', 'click', function(value, index){ var saveParams = { "ConfirmBeforeSave": true, "CustomSave": true, "ValidateForm": true, "Redirect": true }; sfSaveForm(saveParams, function(){ // do anything more before the form saves }); });

Example 2

Consider the example above. If the user should be allowed to change the status of the form while saving it,

sfRegisterFieldCallback('control_skipandcontinue', 'click', function(value, index){ var saveParams = { "ConfirmBeforeSave": true, "CustomSave": false, "ValidateForm": true, "Redirect": true }; sfSaveForm(saveParams, function(){ // do anything more before the form saves }); });