Your validation issues stem from three critical areas that need to be addressed comprehensively for reliable form validation in Service Cases.
First, form event handling in Adobe Experience Cloud aec-2022 requires understanding the platform’s event lifecycle. The standard addEventListener approach you’re using only captures user-initiated submit events through button clicks. However, Service Cases forms can be submitted programmatically through multiple pathways: quick-create shortcuts, automated workflows, API calls, or even other custom scripts calling form.submit() directly. None of these trigger the submit event listener. You need to intercept the actual form submission at a lower level:
const originalSubmit = HTMLFormElement.prototype.submit;
HTMLFormElement.prototype.submit = function() {
if (this.id === 'caseForm' && !validateCustomFields(this)) {
return false;
}
return originalSubmit.call(this);
};
This overrides the submit method itself, ensuring validation runs regardless of how submission is triggered.
Second, custom JS validation needs proper error feedback and state management. Your current implementation prevents submission but may not be providing clear user feedback about why. Implement a validation state object that tracks which fields failed validation and display inline error messages. Also ensure your validation logic handles edge cases like disabled fields, hidden fields, and dynamically added form elements that appear after initial page load.
Third, browser compatibility is crucial for production reliability. The querySelector and addEventListener methods work well in modern browsers, but form validation behavior varies significantly across browser versions. Safari, in particular, has quirks with form event timing. For maximum compatibility, attach validation to both the submit event AND the form’s onsubmit attribute as a fallback. Additionally, test with browser developer tools’ network throttling enabled - slow connections can cause timing issues where validation scripts haven’t fully loaded before users submit forms.
Implement a hybrid approach: override the submit method for programmatic submissions, use event listeners for user interactions, and add inline validation that runs on field blur events to catch errors earlier. This three-layer strategy ensures your business rules are enforced consistently across all submission pathways and browser environments.
This draft is based on general Adobe Experience Cloud knowledge. It has not been verified against your specific version and environment. Practitioners: verify the steps and share your experience below.