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

来源:互联网 发布:java throwable 编辑:程序博客网 时间:2024/05/18 06:27

  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

原创粉丝点击