转:InfoPath 中,如何限制 Contact Selector 控件中输入的用户数量? Validate the Contact Selector in InfoPath – Limit the number of names a user can
2009-11-04 12:03
477 查看
Validate the Contact Selector in InfoPath – Limit the number of names a user can enter into the Contact Selector |
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 particularly want 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.
Firstly, add 2 new fields to your data source:
'EmployeeNameCount' - This field is going to record the number of names that have been entered in the contact selector.
'EmployeeName' – 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 should look similar to this:
Next we need to perform a count on the 'Person' repeating group and record this number in the 'EmployeeNameCount' field.
Double click on the 'EmployeeNameCount' 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 should look like this:
Click on Ok to save the changes you have made to the 'EmployeeNameCount' field
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 should notice that the number in the EmployeeNameCount field corresponds with the number of names entered in the contact selector.
You can now delete the 'EmployeeNameCount' field from the form canvas (but leave the field in the form's data source)
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 'EmployeeName' 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 'EmployeeName' 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 Tip' field enter "Only 1 employee name is allowed. Please remove excess names."
Your validation condition should look like this:
Click on Ok to save the validation and then Ok again to save the changes to the field's properties.
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 should look similar to this:
Earlier on in this blog I said I prefer to put the validation on the 'EmployeeName' field rather than the Contact Selector itself. My reasoning behind this relates to the error message above. Notice that it includes 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.
Another thing that you can do to notify 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.
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 should look like this:
Click on Ok 3 times to save the changes
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 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 'EmployeeNameCount' field, all it involves is setting up the correct validation conditions. Get creative and see what you can come up with.
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
相关文章推荐
- 转:InfoPath 中,如何验证 Contact Selector 控件是否输入了有效值,或如何强制输入? Validate the Contact Selector in InfoPath – Make the Contact Selector Man
- "Your computer could not be joined to the domain. You have exceeded the maximum number of computer accounts you are allowed to create in this domain. Contact your system administrator to have this limit reset or increased."
- 转:Infopath Repeating Table 如何控制最大行数? Limiting number of repeating tables a user can add
- 如何处理 android 方法总数超过 65536 . the number of method references in a .dex file exceed 64k
- Is there a limit to the number of columns in an HBase row?
- 【POI】导出xls文件报错:The maximum number of cell styles was exceeded. You can define up to 4000 styles in a .xls workbook
- 单元测试过多,导致The configured user limit (128) on the number of inotify instances has been reached.
- Flex中如何通过设置restrict属性在TextInput控件中限制用户可以输入的字符串的例子
- poi导出excel报The maximum number of cell styles was exceeded. You can define up to 4000 styles in a .xl
- The user limit on the total number of inotify watches was reached; increase the fs.inotify.max_user_
- Flex的NumericStepper控件中如何通过maxChars限制用户可以输入数字最大位数的例子
- 如何调整Dreamhost主机PHP上传尺寸的限制/How to change the maximal size of uploading in your Dreamhost
- The maximum number of processes for the user account running is currently , which can cause performance issues. We recommend increasing this to at least 4096.
- powerpivot 2013 已超出每个用户的最大允许会话数 The maximum numberof allowed sessions for each user has exceeded
- 如何处理 android 方法总数超过 65536 . the number of method references in a .dex file exceed 64k
- Mysql创建用户后,执行grant授权命令,提示can't find any matching row in the user table
- The number of method references in a .dex file cannot exceed 64K.
- JQuery textlimit 显示用户输入的字符数 限制用户输入的字符数
- Open your rolodex from InfoPath using the Contact Selector
- User Exit to Modify the serial Number in Production Order