Go to: In infopath, how do I limit the number of users entered in the contact selector control? Validate the contact selector in infopath-limit

Source: Internet
Author: User

 

Validate the contact selector in infopath-limit the number of names a user can enter into the contact Selector

I have to admit (even though it sounds really geeky) to my new love affair with the contact selector in infopath. I 've always known it was there and have used it on numerous occasions but did find it a little bit limited. lately, I 've taken the time to actually look at the control properly and I 've been pleasantly surprised with what I have been able to achieve. in my next few blogs, I'm going to cover some cool things that I have discovered with the control while at the same time hopefully answering some commonly asked questions for the infopath users out there.

This first post tries to answer the question-'How can I limit the number of names that can be entered into the contact selector in my infopath form? 'I ve seen a couple of answers, none that are simple, some that even involve code. i'm no coder (and don't particle to be), so here is a simple solution that utilises the 'Count' function and some validation conditions... Yep, that's right, no code.

There are plenty of blogs out there that describe how to set up the contact selector in your infopath form so I won't bother documenting that here. If you need help, check out this blog.

After you have added your contact selector to the form, it will most likely look something like this:

 

Your data source will look similar to this

 

Note: check to make sure your contact selector is working correctly before continuing with this blog.

 

As this is an expense claim, I only want the user to be able to enter one name into the contact selector. if you play around with the control, you'll find it's not as simple as just adding validation directly to the contact selector. to do this we need to add a couple extra fields to the form's data source.

  1. Firstly, add 2 new fields to Your Data source:
  • 'Ployeenamecount'-this field is going to record the number of names that have been entered in the contact selector.
  • 'Ployeename'-this field will perform the validation check.

 

To add a new field, click on the "myfields" group in your datasource

 

Then click on 'add new field or group'

 

Enter a name for your field and then click on OK when you are done

 

After you have finished adding both fields, your data source shoshould look similar to this:

 

 

  1. Next we need to perform a count on the 'person 'repeating group and record this number in the 'ployeenamecount' field.

    Double click on the 'ployeenamecount' field to open the field's properties

    Click on the 'fx 'button to insert a function

    Insert a count function and point to the 'person 'repeating group in your data source, then click on OK. Your function shocould look like this:

     

    Click on OK to save the changes you have made to the 'ployeenamecount' Field

     

     

  2. At this point you might like to test that the employeenamecount field is doing what it's supposed to do. To test, drag the 'employeenamecount' field onto the form canvas.

     

    Preview your form and then enter a couple of names into the contact selector. You shocould notice that the number in the employeenamecount field corresponds with the number of names entered in the contact selector.

     

    You can now Delete the 'ployeenamecount' field from the form canvas (but leave the field in the form's data source)

     

  3. Now we have a field counting the number of names entered in the contact selector, it is easy to set up validation to stop the user from entering more than one name. I prefer to set the validation check on the 'ployeename 'field that we created at the start of this blog versus on the contact selector field itself. there is a good reason for this which I will explain later. but firstly, let's set up the validation rule.

     

    Double click on the 'ployeename' field in the data source to open the field's properties.

     

    Click on the validation tab and then click 'add'

    Set the condition"Employeenamecount is greater than 1"

    In the 'screen title' field enter"Only 1 employee name is allowed. Please remove excess names ."

    Your validation condition shocould look like this:

     

    Click on OK to save the validation and then OK again to save the changes to the field's properties.

     

     

  4. Publish your form, enter 2 names into the contact selector and then try to submit.

    If you are using a browser enabled form, the validation error message you get shoshould look similar to this:

     

    Earlier on in this blog I Said I prefer to put the validation on the 'ployeename' field rather than the contact selector itself. my reasoning behind this relates to the error message above. notice that it should des the name of the field that holds the error. 'employee name' makes it easy for the user to identify the field with the error. if you place the validation condition on one of the contact selector fields such as 'displayname' it is not very intuitive.

     

  5. Another thing that you can do to your y your users of the validation error is to include an error warning next to the contact selector on the form canvas.

    On your form canvas, insert a Section and in the section enter"* Only 1 employee name is allowed. Please remove excess names." Make the contact selector mandatory

    You might like to highlight the text in red and make it italics so it stands out.

     

  6. Double click on the section you added to open the group properties

    Click on the display tab and then click 'Conditional formatting'

    Click on 'add'

    Set the condition"Employeenamecount is less than or equal to 1"

    Tick the 'hide this control' checkbox

    The condition shoshould look like this:

     

    Click on OK 3 times to save the changes

     

  7. Publish your form, enter 2 or more names into the contact selector.

    Notice that when you enter more than 1 Name the error message is displayed, making it easy for a user to identify the cause of the validation error.

     

    If your form is client based (vs browser enabled) then it is essential that you put this extra error warning on the form canvas. validation errors in a client based form do not point the user to the field that is causing the error making it kind of confusing for someone when they are filling out the form.

 

That's it-You 've ve finished. this method can be used to achieve other things as well. say you wanted to enforce the user to input at least 2 names into the contact selector .... As long as you have the 'ployeenamecount' field, all it involves is setting up the correct validation conditions. Get creative and see what you can come up.

 

Upcoming posts:

  • Use the contact selector to obtain other user details such as department, office and manager from the profile database
  • Validate the name entered in the contact Selector
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.