- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2024 06:06 PM
Only one error message is displayed at onSubmit.
When I resolve one error, another error appears.
If there is an error in two items, I want to display the error messages for both items at the same time at onSubmit.
Please let me know if you know how.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2024 07:17 AM
@user_ms Here is the updated script, it will hold the form submission until the error is corrected.
function onSubmit() {
g_form.clearMessages();
var fieldArray = ['test1', 'test2'];
var regex = /^[0-9]+$/;
var errorCount= 0;
for (var i = 0; i < fieldArray.length; i++) {
if (!regex.test(g_form.getValue(fieldArray[i]))) {
g_form.showFieldMsg(fieldArray[i], 'error!', 'error');
errorCount++;
}
}
if(errorCount==0){
return true;
}
else{
return false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2024 05:05 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2024 08:32 PM
hi
function onSubmit() {
var errorMessages = [];
var item1 = gForm.getValue('item1');
if (!item1) {
errorMessages.push('Item 1 cannot be empty');
}
var item2 = gForm.getValue('item2');
if (!item2) {
errorMessages.push('Item 2 cannot be empty');
}
if (errorMessages.length > 0) {
gForm.addErrorMessage(errorMessages.join('\n'));
return false;
}
return true;
}