I wanted to implement the custom validation, but promise based. I was not able to introduce it via custom validator, I think its not asynchronous. (maybe I'm wrong? Can I invoke pnp and chain it in validator?)
Documentation states that spBeforeSave can return promise.
Since throw error does not stop the process of saving the form for me, I had to do a lot of workarounds and:
- introduce global variable storing validation error,
- introduce custom validator that checks this global variable and shows error if any present,
- disable Save button and provide custom button that invokes my own 'validateMyForm()' function, where I can asynchronously query rest services, and chain next promises that leads to form saving (custom validator before, naturally).
Maybe there is something wrong in my understanding, but I could not find anything on forum nor documentation about async validation with promises.