How can verify if the InfoPath form is valid before saving it.

G

G. Tarazi

Hi




I have created an event handler to capture the save button, and redirect it to save using custom code.




When I try to save an invalid document, I have a dialog box that is warning me that some of the values are not valid, this is nice, but the problem is that this box has a yes and no buttons




"This form contains validation errors, errors are marked with wither a red asterisk (required fields) or a red, dashed border (invalid values)."




And if the user presses yes, the form will save the invalid values




The question is how I can find out if there are any invalid values in the form before saving. (Marked invalid by the InfoPath validation itself)




Thanks
 
G

G. Tarazi

fiund this one too :)

XDocument.Errors.Count > 0

"G. Tarazi" <Tarazi (at) LiveTechnologies.ca> wrote in message Hi




I have created an event handler to capture the save button, and redirect it to save using custom code.




When I try to save an invalid document, I have a dialog box that is warning me that some of the values are not valid, this is nice, but the problem is that this box has a yes and no buttons




"This form contains validation errors, errors are marked with wither a red asterisk (required fields) or a red, dashed border (invalid values)."




And if the user presses yes, the form will save the invalid values




The question is how I can find out if there are any invalid values in the form before saving. (Marked invalid by the InfoPath validation itself)




Thanks
 
N

Nick

Im sure by now you have the answer, but for anyone else who has this question:

thisXDocument.Errors.Count > 0, then you have errors.
 
N

Nick

Ok, here is my problem with this:

Before the custom save handler is envoked, this Yes / No dialog box
described below is invoked. I need to learn how to avoid this. We have a
scenario where the form overall may have errors, but we only care about
certain views which are applicable only under certain conditions. So
basically, is there any way to turn off this validation warning which shows
up prior to the actual save handler?
 
A

Alex [MSFT]

Simply modify all your validation expressions to include another variable:

(your expression) AND doCheck = 1

Then, when in your Save handler, set doCheck to 1 - this will cause all
validations to happen.

Good luck,
Alex @ Microsoft
 
N

Nick

Alex-

This will not work. As I had stated, the problem lies in the fact that
Yes/No happens BEFORE the save handler. I need to find a way to disable this
message, then use whatever code I need in the handler.

Thanks,
Nick
 
A

Alex [MSFT]

Create a button on the bottom of the form that allows the users to save the
form. This button will set doCheck = 1 and then look at
XDocument.Errors.Count. If it is = 0, it will call XDocument.Save().

Good luck.
Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top