Required Controls Left Blank But Can Still Submit - InfoPath Dev Sign in | Join | Help in General InfoPath (Entire Site) InfoPath Dev InfoPath Dev is dedicated to bringing you the information and tools you need to be successful in your Microsoft Office InfoPath development projects. Home Blogs Forums Photos Downloads InfoPath Dev » InfoPath » General » Required Controls Left Blank But Can Still Submit Required Controls Left Blank But Can Still Submit Last post 04-24-2006 06:31 PM by Matt Faus. 22 replies. Page 1 of 2 (23 items) 1 2 Next > Sort Posts: Oldest to newest Newest to oldest Previous Next 04-19-2006 10:38 AM CycleFitness Joined on 03-17-2006 USA Posts 80 Required Controls Left Blank But Can Still Submit Reply Contact I have form with numerous required controls. My Submit button uses Rules and Code as follows:Rule 1 - Submit to Data ConnectionCode - Close App.I would like it to behave so that if the user doesn't enter all the required information, they can't submit the form. I tried modifying the Submit button this way:Rule 1 - Long list of OR conditions that check whether fields (is blank). If any are blank a dialog message displays. I checked the "Stop processing Rules when this rule finishes" box. The only problem is that the code then executes which closes the application, so right after the dialog appears the app closes. How do I truly "require" fields have values?I must be missing something real simple, here. This can't be this complicated. ;-)Thanks, Deb! 04-19-2006 10:43 AM In reply to Greg Collins Joined on 08-08-2006 Posts 2,126 Re: Required Controls Left Blank But Can Still Submit Mark as Not AnswerMark as Answer... Reply Contact You should be able to set up your submit to close on success so you don't have to do that in code.Also in code you can check the Errors count before deciding to close. Please Visit:BraintroveGreg's Paintings 04-19-2006 11:19 AM In reply to CycleFitness Joined on 03-17-2006 USA Posts 80 Re: Required Controls Left Blank But Can Still Submit Mark as Not AnswerMark as Answer... Reply Contact Can you tell me more about either of these options? I'm relatively new (perhaps obvious by the number of posts) and have no coding knowledge.Two points I'd like to clarify; 1) In the Submit button properties all Rules execute before Code, correct? It's kind of odd that they put the Code button on top of the Rules button. It gives you the impression they run in that order.2) Should setting the "cannot be blank" value do something? I see red asterisks in Preview, but there is no other event unless I specifically set up a dialog message to appear.Thanks. 04-19-2006 10:06 PM In reply to Patrick Halstead Joined on 08-08-2006 Posts 5,112 Re: Required Controls Left Blank But Can Still Submit Mark as Not AnswerMark as Answer... Reply Contact Hi Deb,It's either Rules or Code, but there is a way to call Code from Rules. I posted on this a few days ago, but there is a better example at:http://blogs.msdn.com/infopath/archive/2005/06/17/430347.aspx . You only get to call code in the Condition (not in the Actions). Hope this helps! Patrick HalsteadProject Manager at Qdabra 04-20-2006 05:35 AM In reply to JimDandy Joined on 02-10-2006 Posts 24 Re: Required Controls Left Blank But Can Still Submit Mark as Not AnswerMark as Answer... Reply Contact I think the period at the end of the link above has made itself a part of the hyperlink which prevents the link from working properly. 04-20-2006 07:41 AM In reply to CycleFitness Joined on 03-17-2006 USA Posts 80 Re: Required Controls Left Blank But Can Still Submit Mark as Not AnswerMark as Answer... Reply Contact Thanks for the information, Patrick. I'm still a little confused. First, I'm curious why I even have to get into all of this. I have controls that require values. I have a Submit button which has a Rule to Submit and then Code to close the app (they both execute, although you mentioned it's either one or the other?). Why does InfoPath let the user Submit if the user hasn't provided values for the required fields?Second, assuming there is no other way to configure my required controls and I have to go down this code path, I still need to clarify your statement that it's "either rules or code." I do have both and both seem to execute. Even if I use the "stop processing rules" option, the code executes that closes InfoPath. I have this statement in the Code to close InfoPath: Application.ActiveWindow.Close(true);<aside> It's odd InfoPath offers an option through its interface to close the form, but not one to close the app. Leaving a non-InfoPath user in InfoPath after submitting a form is very confusing to them. THis is why I had to get into the code, which was provided by a user on this forum earlier on.</aside>So, you mentioned in your explanation that you are "calling code through Rules." You're using the xdExtension namespace. Does your book explain any of this? I am reading it online through InformIT. Third,with the ability to call code from Rules, I still wouldn't have a clue how to write the code. Greg mentioned checking the error count before closing. What would be the code for that? I'd like to learn for myself as well. What's the best resource for learning this skill?Thanks so much for your help, Patrick. 04-21-2006 11:17 AM In reply to Greg Collins Joined on 08-08-2006 Posts 2,126 Re: Required Controls Left Blank But Can Still Submit Mark as Not AnswerMark as Answer... Reply Contact Deb,Let's start over with a few things.1. You have no reason, with your form, to be calling into code from your rules. Let's just leave that alone.2. Selecting the Cannot Be Blank check box: This puts red asterisks on fields so the user knows that they have to fill those out. You say you have required fields, well each of those should have this check box selected. If you have this check box selected, the submit will fail if the user doesn't fill in those fields. Without it, the submit will continue (assuming it passes your rule conditions) regardless of whether you have some text on the screen saying they have to fill those out.3. Rules execute first, and then code.4. Regardless of wether your rules finish, the code will always be run.5. There is a close option in the rules.6. You cannot give a good error messge to your user if you submit via rules and the submit failes.7. In code you can simply check if there are any errors in the Errors collection instead of making a huge list of required fields (assuming you used the Cannot Be Blank check box).Okay -- all of this adds up to 2 things:1. Either add the close function to your rules for once the submit occurs, and get it out of your code.2. (preferable) Move your submit to code so that you can catch any error that occurs if the submit fails and give a useful error message to your users, and decide whether to close the form based on a successful submit. Please Visit:BraintroveGreg's Paintings 04-21-2006 03:43 PM In reply to CycleFitness Joined on 03-17-2006 USA Posts 80 Re: Required Controls Left Blank But Can Still Submit Mark as Not AnswerMark as Answer... Reply Contact Thanks for attempting to help clear the smoke, Greg. I'll respond by your numbered replies.1. Bless you.2. I do have the "cannot be blank" checkboxes checked. The submit does fail, but the user doesn't see it because the close application code runs and "poof" it's over.3. Thank you for the clarification. That's the behavior I was seeing.4. Yes, that's what I experienced.5. The close option in the Rules only closes the form. It leaves you in InfoPath, though, which is very confusing to a user.6. Yeap. I realize that now. Thanks.7. I wish I knew how to do that. Can you give me a resource to study?I don't know how to do either of the options you mention. the first is to add the Close function to Rules. Does this mean using the technique Patrick eluded that that involved a namespace? And adding an error trap with message box, together with Submit would require coding knowledge. Again, if you could point me to some examples of how to use the Error collection and how to Submit via code, I can study them.Thanks for your patience. I really got myself tangled up here. If the app would close after submit, none of this would be an issue. 04-21-2006 04:00 PM In reply to CycleFitness Joined on 03-17-2006 USA Posts 80 Re: Required Controls Left Blank But Can Still Submit Mark as Not AnswerMark as Answer... Reply Contact I've given this a college try -- searching the InfoPath TechNet forum and looking at the Developer's reference. Something like this would work, I guess, but I have the syntax all wrong:function CTRL19_5::OnClick(eventObj){if (XDocument.Errors.Count >; 0) XDocument.UI.Alert("Required information is missing.") returnelse XDocument.Submit() Application.ActiveWindow.Close(true);}How would I fix this to work? 04-21-2006 10:51 PM In reply to Patrick Halstead Joined on 08-08-2006 Posts 5,112 Re: Required Controls Left Blank But Can Still Submit Mark as Not AnswerMark as Answer... Reply Contact Hi Deb,I thought you were trying to do both code/rules from the button properties dialog. I didn't realize you had already defined an OnClick handler. In that case, yes, they will both run, as Greg says. I really think you're better off just doing rules. Why do you need code? Patrick HalsteadProject Manager at Qdabra 04-23-2006 03:01 PM In reply to CycleFitness Joined on 03-17-2006 USA Posts 80 Re: Required Controls Left Blank But Can Still Submit Mark as Not AnswerMark as Answer... Reply Contact I need the rules so I can get InfoPath to close itself when the user Submits. The Submit options only support closing the form. In my case, that causes confusion for the users who don't know anything about InfoPath.Is there another way to do this? If there is, then I can eliminate the code and my form should then behave as I would expect and not allow a user to submit if they haven't provided required field values. With the code, even if they didn't, it runs the code and closes the app.Thanks, Patrick. 04-23-2006 11:28 PM In reply to Patrick Halstead Joined on 08-08-2006 Posts 5,112 Re: Required Controls Left Blank But Can Still Submit Mark as Not AnswerMark as Answer... Reply Contact Hi Deb,Add an action to "Close the Form" after your "submit" action. Patrick HalsteadProject Manager at Qdabra 04-23-2006 11:39 PM In reply to Stephanie Cantwell Joined on 08-07-2006 Sammamish, Washington Posts 139 Re: Required Controls Left Blank But Can Still Submit Mark as Not AnswerMark as Answer... Reply Contact I think Deb is correct. Close the From action only closes the form itself, not the InfoPath application. You still need the Application.ActiveWindow.Close(true) to close the application. Stephanie Cantwell / Test ManagerQdabra® Software / Streamline data gathering to turn process into knowledge 04-24-2006 03:43 AM In reply to AndersR Joined on 10-20-2005 Denmark Posts 138 Re: Required Controls Left Blank But Can Still Submit Mark as Not AnswerMark as Answer... Reply Contact [OFF-TOPIC]gratz, scantwell! 0-100 posts in record time ;-) 04-24-2006 07:14 AM In reply to CycleFitness Joined on 03-17-2006 USA Posts 80 Re: Required Controls Left Blank But Can Still Submit Mark as Not AnswerMark as Answer... Reply Contact With that need now clear, can someone help me write two pieces of code:1) Check for any errors (required fields without values) and if found, display message 'required information missing', and return user to the form. If not found, submit the form and close the application. Page 1 of 2 (23 items) 1 2 Next > Copyright © 2003-2019 Qdabra Software. All rights reserved.View our Terms of Use.