Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
**Client Script**
# Mandatory Field Check on Form Change

Client script which is showing how to use g_form.mandatoryCheck() function, which allows to easily detect if any of mandatory field is not filled on record.
This client script demonstrates how to use `g_form.mandatoryCheck()` to validate whether all mandatory fields on a form are filled.

**Example configuration**
It is typically used in an **onChange** catalog client script to trigger validation when a specific field changes.

![Coniguration](ScreenShot_1.PNG)
If mandatory fields are missing, the script:
- Displays an info message listing the missing fields. Note: the red message is the existing functionality that will give you an error message.
- Visually highlights each missing field using a flashing effect to guide the user.

**Example execution**
This approach improves user experience by clearly indicating which fields require attention.

![Execution](ScreenShot_2.PNG)
**Example configuration**
<img width="1122" height="638" alt="image" src="https://github.com/user-attachments/assets/31f86ae7-27fe-4921-8d8b-391eaa55304d" />

**Example execution**
<img width="1029" height="495" alt="image" src="https://github.com/user-attachments/assets/b8384507-4292-41f4-9155-9be10195493e" />
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}

//Client script, which shows how to use mandatoryCheck() function
//mandatoryCheck() allows validating if all mandatory fields are filled
//If all mandatory fields are filled it return true, otherwise it returns false
if (isLoading || newValue === '') {
return;
}

//Check if all mandatory fields are filled on record
// Check if all mandatory fields are filled
if (!g_form.mandatoryCheck()) {

//Example action when not all mandatory fields are filled - display message and remove state field
//if not get all missing fields
var missing = g_form.getMissingFields();
g_form.addInfoMessage("State field removed, because not all mandatory fields are filled: " + missing);
g_form.setDisplay('state', false);
//Info message displaying the fields that are missing
g_form.addInfoMessage("Please complete the following mandatory fields: " + missing.join(", "));
//go through missing fields and flash them
missing.forEach(function (fieldName) {
g_form.flash(fieldName, "#FFFACD",0); // Flash to draw attention
});
}

}
Loading