-
-
Notifications
You must be signed in to change notification settings - Fork 11
13. Layout for Java Script code
JoomlaBoat, LLC edited this page Jan 9, 2025
·
6 revisions
Java Script Layout Tab inserts provided code before tag.
There is a method to create or update table records using JavaScript. CustomTables handles data sanitization and validation.
Example HTML(Desktop) layout tab:
<button onClick="SaveMe();" class="btn">Save Me</button>
Example Java Script layout tab:
function SaveMe()
{
const record = new CustomTablesEdit();
//Save record
record.saveRecord('/phone-book',{ 'name': 'Ivan', 'email': 'info@ct4.us' },36);
//Reload table row
record.reloadRecord(36);
}
The CustomTablesEdit
class is a JavaScript utility for handling operations on table records in web applications.
-
Parameters:
-
url
(string): The endpoint for the save operation, Menu Item alias. Example: "/index.php/phone-book" or "/phone-book" -
fieldsAndValues
(object): An object containing field-value pairs to be saved. -
listing_id
(number): The ID of the record being edited. -
successCallback
(function): Optional. Function to execute on successful save. -
errorCallback
(function): Optional. Function to execute on error.
-
-
Description: Saves the provided data to a specified record. It sends a POST request with the fields and values that need to be updated. On successful completion, the
successCallback
is invoked, and on error, theerrorCallback
is called.
-
Parameters:
-
listing_id
(number): The ID of the record to reload.
-
-
Description: Reloads a particular table row (record) after changes have been made. It identifies the table and the specific row based on the provided
listing_id
and then triggers a refresh to update the displayed data.
// Creating an instance of CustomTablesEdit
const record = new CustomTablesEdit();
// Saving a record
function SaveMe()
{
const record = new CustomTablesEdit();
//Add new record
record.saveRecord('/test-fields-1',{ 'text': 'Ivan', 'email': 'support@joomlaboat.com' },null,
function success(data) {
console.log('Record saved successfully', data);
alert("New record ID: " + data.id)
},
function error(data) {
console.error('Failed to save record', data);
});
}