Preventing the manual closing of a dialog

Hi,

I have a dialog box that shows when the user creates a new record (pictured below).

If the user clicks the Okay button, it runs some validation to make sure everything has a value and, if everything checks out, closes the dialog box.

If the user presses “cancel”, it deletes the record and closes the dialog box.

The problem is, if the user presses escape, they can close the window without deleting the record and without going through the “Okay” validation.

How should I approach this?

Thanks,
Andrew

Hi, there is an event, can’t remember the exact one, possibly ‘onhide’. You attach a method which returns false when you don’t allow the window to close…

An easy way to go around is to start a transaction before opening the dialog box, create the new record, open dialog window and make a rollback.

Example :

databaseManager.startTransaction()
controller.newRecord()
//Open special form to create new record
application.showFormInDialog( forms.Add1Contact ,  -1,-1,-1,-1, null ,  true,  false,  true)
//The transaction will be committed before quit Add1Contact, if not rollback
databaseManager.rollbackTransaction()

You just commit the tansaction at the end of method behind the Okay button.

Example:

//Put all the element names on an array
var ElementsA = elements.allnames

// Retrieve all mandatory fields and put them on an array (Get a dataset based on query)
var maxReturnedRows = 1000;
var query = "select fldu_t_fieldname,fldu_b_fieldfill from fldu_fields where fldu_b_fieldfill = 'Y'"
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(), query, null, maxReturnedRows);

//Put all mandatory fields from application in an array
var mandatoryFieldsA = dataset.getColumnAsArray(1)

//Initialise counter of fields not filled
var ctr = 0

//test your fields

if (ctr > 0)
	{
	plugins.dialogs.showErrorDialog( 'Input error' ,  'Red fields should be filled' ,  'Ok')
	}
	else
	{
	databaseManager.commitTransaction()
	application.closeFormDialog()
	}

Like this the record is created like you want or deleted.

I hope it can help you.

DomTom.