Hello,
I have a Web Form with several different steps.
The second to the last step surfaces a form that only displays a subgrid.
I would like to prevent the Submit button from executing the submit/save action if there are no related records in the subgrid.
Previously, I was able to accomplish this by inserting the following code into the Web Form Step -> Form Options -> Custom Javascript.
if (window.jQuery) {
(function ($) {
if (typeof webFormClientValidate != "undefined") {
var originalValidationFunction = webFormClientValidate;
if (
originalValidationFunction &&
typeof originalValidationFunction == "function"
) {
webFormClientValidate = function () {
originalValidationFunction.apply(this, arguments);
// do your custom validation here
const tableBody = document.querySelector(
".view-grid > table > tbody"
);
// the tbody element isn't created if there are no records.
if (!tableBody) {
alert("You must add at least one requested service.");
// return false; // to prevent the form submit you need to return false
return false;
}
// end custom validation.
return true;
};
}
}
})(window.jQuery);
}
The code was originally lifted from here.
When the user would click Submit with 0 records added, the standard Alert would appear informing the user that at least 1 record must be included in the subgrid. Worked like a charm.
However, today I noticed that this is no longer working. The form just submits and doesn't seem to pay any mind to this custom validator.
Can someone please assist? The goal is to prevent the Submit button from executing if there are no records in the subgrid.
