0

We need to capture errors on Sitecore form after Submit button click. Below code return 0 value in console log on first attempt and that might be because errors appear only after submit click. In subsequent click we can see value in console log. One solution is to create a new function, use setTimeout function, set 2-3 seconds delay and write whole logic in new function. Is there any other better approach to capture errors on submit click?

$("form").on("submit", function () {
    console.log($(this).find(".validation-summary-errors .list-group li").length)
});

1 Answer 1

0

Sitecore forms uses an unobtrusive form validation library that's dependent on jQuery, to read validation messages, you need to apply the trick prior to DOM ready and certainly NOT in (document).ready.

Please refer to this article to understand unobtrusive validators. here is the link

2
  • Actually that post describes the process for some custom client validation in form and that should be applied on page before DOM ready which is fine but here I think we need to do something after DOM ready because error message only appear after Submit click. For example on page load .validation-summary-errors class doesn't exist. Hope that make sense.
    – Sukhjeevan
    Jun 8, 2023 at 14:33
  • Or might be if there is any option to add a callback function that should trigger after Submit event and we can write logic in callback function
    – Sukhjeevan
    Jun 8, 2023 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.