Form Customization
Form customization allows developers to modify, validate, and enrich form data during rendering or submission. This ensures that users interact with a well-structured, context-aware, and validated form interface.
changeData
This function is used to modify the data fetched from the database before it is displayed to the user.
For example, you can append units (e.g., "Kg") to a numeric value or fetch static data from another table and include it as a column value.
Use Case: Transforming or enriching data for better readability or context.
validateData
This function is used to validate the values entered by the user in the form.
It ensures that the entered data adheres to the validation rules defined in the customization code.
Use Case: Checking if user inputs meet specific criteria, such as numerical ranges or required formats.
validateSchema
This function is used to validate the form's schema, ensuring it meets the necessary structure and validation requirements.
Use Case: Updating or verifying the schema associated with the form to maintain consistency and accuracy.
Sample Implementation
Below is a sample implementation of form customization in Supista ERP:
function validateData(data) {
return data;
}
function validateSchema(data) {
return data;
}
function changeData(data) {
return data;
}
async function customizeERP(userData, apiOperations) {
// Your Code Starts Here
const tableName = "Your Table Name";
const { __d3__formData, __d3__error, __d3__schema } = userData;
let newData;
newData = validateData(userData);
newData = validateSchema(userData);
newData = changeData(userData);
return newData;
}
Output Structure
{
"__d3__formData": {},
"__d3__error": {},
"__d3__schema": {}
}
Example Code
function changeData(userData) {
const data = {
...userData,
"__d3__formData": {
...userData?.__d3__formData,
"name": userData.__d3__formData.name.toUpperCase()
}
};
return data;
}
async function customizeERP(userData, apiOperations) {
const tableName = "table_name";
let newData;
newData = changeData(userData);
return newData;
}
Example Input
{
"__d3__formData": {
"name": "johndoe",
"email": "johnDoe@gmail.com"
},
"__d3__error": {},
"__d3__schema": {}
}
Example Output
{
"response": {
"__d3__result": {
"__d3__formData": {
"name": "JOHNDOE",
"email": "johnDoe@gmail.com"
},
"__d3__error": {},
"__d3__schema": {}
},
"__d3__error": false,
"printConsole": []
}
}