转:InfoPath 中,如何验证 Contact Selector 控件是否输入了有效值,或如何强制输入? Validate the Contact Selector in InfoPath – Make the Contact Selector Man

本文介绍如何在InfoPath表单中设置联系人选项为必填项,包括添加验证规则及错误提示的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

Validate the Contact Selector in InfoPath – Make the Contact Selector Mandatory (version 2)

Here is a very quick and simple method of making your contact selector in your InfoPath form mandatory.

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.

 

  1. Firstly, add a new field to your data source called 'EmployeeName'. This will be the field that performs 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 the field, your data source should look similar to this:

     

     

  2. Next we are going to set the 'EmployeeName' field to equal the display name entered in the contact selector.

    Double click on the EmployeeName field to open the properties

    Set the default value of the field to 'DisplayName'

     

     

  3. Now that the 'EmployeeName' equals the DisplayName all we need to do is set a validation rule on the EmployeeName so that it can never be blank.

    Click on the 'Validation' tab in the EmployeeName field properties

    Click on Add. Then set your validation rule as shown below.

    Click Ok and Ok again to save the changes

     

    I always put any validation rules for the contact selector on the 'EmployeeName' field rather than on the Contact Selector itself. My reasoning behind this relates to the validation error message that the user sees (below). 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.

    

 

  1. 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 "Cannot be blank"limiting the number of names in the contact selector useful too.

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

     

  2. 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 "EmployeeName is not blank"

    Tick the 'hide this control' checkbox

    The condition should look like this:

     

    Click on Ok 3 times to save the changes

     

  3. Publish your form.

    Open a new form and you should see the error warning next to the contact selector name. If you enter a name into the contact selector, then the error message should disappear.

 

If you found this post useful, you may also find my post on

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值