1. General information
1.1. Description of the control
Each edit form automatically contains an “ActionButtons” control, which consists of three basic buttons needed to work with the form – “Save”, “Delete” and “Back”.
2. List of tabs in the control settings dialog
- General – Setting general properties
- Save – Save button settings
- Delete – “Delete” button settings
- Back – “Back” button settings
- Below the script of each event (“OnAfterOpen”, “OnBeforeSave”, “OnAfterSave”, “OnBeforeOpen”, “OnBeforeDelete”, “OnAfterDelete”) there is a “Deny script” check box. Checking it turns off running the script, whether the event is triggered in the edit form or otherwise (for example by a multiple change in the view table); the script stays saved.
2.1. “General” tab
2.1.1. Options
- Hide “Save” button
- Checking this box determines whether the “Save” button should be hidden in the edit form.
- Hiding the button does not protect the record against changes – the record can still be saved with the “Save and new” or “Save and continue editing” buttons or with a button with a script. Who may edit the record is determined by the “Editing rights” of the edit form.
- Hide “Delete” button
- Checking this box determines whether the “Delete” button should be hidden in the edit form.
- Unlike the “Save” button, hiding it disables deleting the record in the edit form on the server side as well, and bulk deletion of records in the view table then remains available to administrators only. Deleting a record with a script command is not disabled by it.
- Hide “Back” button
- Checking this box determines whether the “Back” button should be hidden in the edit form.
- Show “Save and continue editing” button
- Checking this box determines whether the “Save and continue editing” button should be displayed in the edit form.
- Show “Save and new” button
- Checking this box determines whether the “Save and new” button should be displayed in the edit form.
- The button text can be set to custom.
2.1.2. OnAfterOpen
- A script that is executed when the record is opened in an edit form.
- The script runs only when the edit form is loaded for the first time. It does not run again after the form is submitted – for example after pressing a button or after an unsuccessful save.
- Database changes made by this script are committed as soon as it finishes, in a separate database transaction.
- Navigation scheduled in this script (SCHEDULEFORM, SCHEDULEVIEWPAGE, SCHEDULEURL, SCHEDULEPORTLETS) and the “HIDEFORM” function are performed only in user mode.
2.2. “Save” tab
2.2.1. JavaScript
- A function call (or another javascript expression) without a semicolon at the end, for example “beforeSave()”, which is evaluated when the “Save” button is pressed. The result is used as a condition, so the function is written including the parentheses – the function name alone without parentheses does not call the function. The “#ng_...#” identifiers in the expression are replaced in the same way as in other JavaScript of the edit form.
- If the return value of the function is “true”, the server script “OnBeforeSave” is executed.
- If the return value of the function is “false”, the server script “OnBeforeSave” will not be executed and the record will not be saved.
- The expression is also evaluated before the record is saved with the “Save and new”, “Save and continue editing” and “Synchronize” buttons, before an automatic saving of a not yet saved record (for example when a nested record is created from a view table of the form), and after pressing a “Button” control of the “Open an edit form” or “Print to template” type; for the “Open a view page” and “Script” types only with step “1. Save the record” or “3. Save the record” checked. For a “Button” control, the expression is evaluated after the code from the “Client” field, and only if that code does not return a value with the “return” command earlier.
2.2.2. OnBeforeSave
- A script that is executed before the record is saved to the database.
- Control validation is completed before this script starts. A required field therefore cannot be filled in only by this script – validation evaluates it as empty.
- Navigation scheduled in this script (SCHEDULEFORM, SCHEDULEVIEWPAGE, SCHEDULEURL, SCHEDULEPORTLETS and others) is not performed. A redirect after saving is scheduled in the “OnAfterSave” script.
- The “OnBeforeSave” script and the record save run in one database transaction. A script error prevents the record from being saved and also rolls back database changes made by this script.
- “SKIPSAVE()” behaves differently from an error: it skips only the record save, commits database changes made by the script, and then runs “OnAfterSave”.
- If the “OnBeforeSave” script is run other than by saving the edit form – by a multiple change or a change of a value directly in the view table, by an import from Excel, or by the “OBSOAS” server function – “SKIPSAVE()” does not perform the changes written by the script commands (“Save value to the database”, “New record”, “Delete record” and other writing commands). Only those of them that the script committed with the “COMMIT()” function are performed.
- In a multiple change of a value from the view table, a script error on an individual record is not shown to the user – the record is not changed and processing continues with the next record.
2.2.3. OnAfterSave
- A script that is executed after the record is saved to the database.
- It starts only after the transaction containing the “OnBeforeSave” script and the record save has been committed successfully.
- The “OnAfterSave” script runs in a new database transaction. An error rolls back database changes made by this script, but it does not restore the already saved record to its previous state.
- Assigning a value to a control of the current record (the “Assign value” command) is not saved to the database in this script, because the record has already been saved. The value of the current record has to be written with the “Save value to the database” command.
2.2.4. OnBeforeOpen
- A script that is executed before a new record is opened in the edit form.
- The “OnBeforeOpen” script is executed after pressing the “Save and new” button in the edit form.
- Navigation scheduled in this script (SCHEDULEFORM, SCHEDULEURL and others) is not performed. If the script ends with an error, the new record is not opened.
2.3. “Delete” tab
2.3.1. JavaScript
- A function call (or another javascript expression) without a semicolon at the end, for example “beforeDelete()”, which is evaluated when the “Delete” button is pressed. The function name alone without parentheses does not call the function.
- If the return value of the function is “true”, the server script “OnBeforeDelete” is executed.
- If the return value of the function is “false”, the server script “OnBeforeDelete” will not be executed and the record will not be deleted.
- If the function is filled in, it replaces the default confirmation of deleting the record – the default confirmation is then not displayed.
2.3.2. Options
- Always allow deleting to the owner or co-owner of the record
- Checking this box determines whether the record owner or co-owner should be allowed to delete the record, regardless of the existence of other controls on the form to which the record owner or co-owner does not have the right.
2.3.3. OnBeforeDelete
- A script that is executed before deleting a record from the database.
- The “OnBeforeDelete” script and the record deletion run in one database transaction. A script error prevents the record from being deleted and also rolls back database changes made by this script.
- “SKIPDELETE()” behaves differently from an error: it skips the record deletion and then runs “OnAfterDelete”. The changes written by the script commands (“Save value to the database”, “New record”, “Delete record” and other writing commands) are not performed; only those of them that the script committed with the “COMMIT()” function are performed.
- A redirect after deleting is scheduled in the “OnAfterDelete” script. Of the navigation scheduled in this script only the SCHEDULEBACK and SCHEDULEURL functions are performed, and only when running the “OnAfterDelete” script is disabled.
2.3.4. OnAfterDelete
- A script that is executed after deleting a record from the database.
- It starts only after the transaction containing the “OnBeforeDelete” script and the record deletion has been committed successfully.
- The “OnAfterDelete” script runs in a new database transaction. An error rolls back database changes made by this script, but it does not restore the already deleted record.
2.4. “Back” tab
2.4.1. JavaScript
- A function call (or another javascript expression) without a semicolon at the end, for example “beforeBack()”, which is evaluated when the “Back” button is pressed. The function name alone without parentheses does not call the function.
- If the return value of the function is “true”, the user is redirected back to the place from which the edit form with the currently open record was called.
- If the return value of the function is “false”, the user will not be redirected back.
2.5. “Save” and “Close” buttons
- “Save” button – Saves changes to the control settings.
- “Close” button – Closes the control settings dialog without saving changes.
3. Examples
3.1. Javascript functions
- attachEvent2(window, 'load', function() { var o = el('btSave'); if (o != null) o.style.display = 'none'; });
- attachEvent2(window, 'load', function() { var o = el('btDelete'); if (o != null) o.style.display = 'none'; });
- attachEvent2(window, 'load', function() { var o = el('btBack'); if (o != null) o.style.display = 'none'; });