0

I'm aware that I could simply override the SaveAction, and provide my own validation for all of the fields, but is there a way to trigger SharePoint's default form validation without actually submitting the form?

Similar questions have been posted here and on other sites, but I have not yet seen a solution which isolates the form's default SharePoint validation.

It would be beyond helpful to understand how to accomplish this, so that I can both share a working solution for a custom attachments table solution with the community and implement this in a SP2013 on prem project I'm currently working on.

Thanks

1

As far as I have been able to tell there is no way to do this. Here is the solution that we were able to come up with.

Basically here is what we did.

  1. Added a required field called ErrorCount and hid it on the form.
  2. Use PreSaveAction to clear that field and call some custom validations that were too tricky to do with built-in SP validation. These validations create similar markup to the validation error/alerts SP would create.
  3. Call SPClientForms.ClientFormManager.SubmitClientForm(formUniqueId) to submit the corm and do the built-in SP validations. This will fail because the ErrorCount field is required but has been cleared by our code.
  4. We can then count the number of error notifications on the page. Using jQuery it looks something like this. $('span[id^="Error_"],span.invalid-text,span.sp-peoplepicker-errorMsg').
  5. If there is only 1 error it is that ErrorCount is required and we put a value in there and SubmitClientForm() again and proceed with regular saving.
  6. If there are more errors we know that other fields aren't valid and can just stop. We also throw an alert and scroll to the first err message.

There are a couple of issues that still don't get caught I think that certain types aren't validated at SubmitClientForm, but over all this has worked well for us.

1
  • Thanks for sharing your response to this issue. I'll happy to share mine if nobody responds with a better one. – alanofranco May 3 '19 at 18:34
0

So I went looking again and found this answer which is based on this blog post.

It is much easier that what we came up with.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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