Friday, June 21, 2013

Make Multi select list box required in InfoPath



In this post we are going to see how we can make multi selection list box in InfoPath required field. Now you must be thinking what is the big deal here?

We are going to have one sample list with a look up field which is multi select.


  Let's add one item and try without adding any city. Remember this is the list form and not the InfoPath.

Great, this has work perfect.



So let's customize this list in InfoPath. Click customize button from the ribbon.



So now InfoPath has converted the multi select lookup to the multi select list box where you will have checkboxes to select.



Publish the form and click on New now.



Seems okay so far. you can see red asterisk sign which indicates its required field. Let us not selected anything just the title and try to see if it saves the item.



so far so good. Let's select items from the city and save the list item. we should be good to go.


Well this is what I was mentioning. You simply cannot submit even though you have selected the items. Even though red asterisk sign goes away but still no luck.

So we are now going to solve this. First you need to remove the required field from the list to make this a required field. We will have to handle the required field from InfoPath and not from the list field. In InfoPath we have to handle multi select lookup like this.

So I have removed the required validation from city field and republish the form.


as you can see now because required field is removed, the asterisk sign is gone.

Go back to the design InfoPath page. add textbox below the list box control. We are going to add validation for the list box.



Click on manage rules by keeping the selection on text box.

Click on add validation.



Click on condition and then select field drop down, from there select field or group.



Now click on show advanced view. Select value inside the City group and then from drop down select number of occurrences.



UPDATE :  USE CONDITION ALL OCCURRENCES ARE BLANK AND NOT NO OF OCCURRENCES <=1. THIS WILL RESOLVE THE ISSUE.

and then less than equal to 1





Right click the textbox and then select property. Set the default text.



Now publish the form. and click on new.



It indicates the required field by red dotted. You can check that by entering title and not selecting any value from the list and then click on save.



As you can see when you select value, the red dotted line goes away which indicates that the condition has been satisfied.



There you go. you now have a required field multi select list box in InfoPath.

UPDATE : The above method will help you when you want to make multi select list box required based on other values / other controls.

However if you want to make it just the required field, then make the following change.

Go to the list settings. go to city field and make it a required field.

Customize the form in InfoPath. Go to the file - form options.

 
then advanced - edit default values - expand the city node and uncheck the value checkbox.






Now publish the form and you should be good to go.

What happens here is when we add the multi-select list box, InfoPath adds one blank node always in the XML DOM. 

so when the field is required, you ideally cannot submit blank value. because one node is blank, InfoPath cannot submit the form and hence we see the message despite of selecting value(s) from the list box.






Thursday, June 20, 2013

Implement Cascading drop down in InfoPath


In this post we are going to see how we can have a cascading drop down. Nothing can be simpler than taking an example of classic country, state and cities.

So let's first create these three list and values with lookup values.

First we will have countries list, then a state which will have country lookup and then city which will have a look up to the state list.

For simplicity I am going to take only two three values in country, two three values in state and two three values in the city list.

Here are how I have set up.

Country


State





City


Now we are going to use these into one more list and then customize the list in InfoPath.

I have order list with me and I have three columns each lookup to respective list title field.



Let's customize the list in InfoPath by clicking Customize form on the ribbon button.



So now we have this. Publish the form back to the SharePoint by clicking on quick publish.



Alright now to the point, we have country which has no dependency, then we have state which has dependency on country and finally city which has dependency on state.

So here we do not need to do anything for the country.

Out of the box we will not have this cascading drop downs. We would need to create two more data sources. One for state and one for city.

So let's go ahead and create those two data sources.

Click on manage data connections. you will see something like this.



Click on add. Select Receive data in next screen. Select SharePoint list and library in next screen.

Click on next and select State list. On next screen make sure that you select these three.



and on final screen give a name of the connection and select automatically get the data when the form is opened.

Now we will repeat the same steps for the city. Create a new connection by clicking on Add on manage data connection window.

Repeat the same steps as we did earlier and this time select city list. Give name and add the connection to the form.



So finally I have something like this.



Now it's time to configure the drop down.

Open the InfoPath page and select state drop down and click on property. Change the data source from state to GetStates and then in value tree, instead of Title select ID.





So it will be like this



Same way change it for the city and it should look like this.



 So far so good. Let's just preview out form and see that we are doing good so far.



Alright we still have not configured the cascading look up. All the above steps which we performed where necessary and now is the time to set it.

Right click on State drop down and select property.

Select entry xPath.



Click on filter data.



Click add and then select this condition.



When you click select field or group, a window opens up.



Now change from GetStates (secondary) to main data source.



Now from main data source select country.



Click on ok three times and then apply and ok.

Repeat the same step for city but this time make sure that for filter condition you select State equals main data source state.





Alright, give it a go this time and see what happens.

Let's try to preview the form and select Australia as country.














There is one more setting we need to do here to make it 100 percent complete.

Select country drop down. click on manage rules. add new action.



Select set field's value.



Set State drop down to blank. Same way also set city field value to blank by adding one more action for country drop down.

Click on ok.

Repeat the same steps for the state drop down. Select state drop down. click on manage rule. Add action. Set field. Select City and set field value to blank.

We did these steps because when we change the country we need previously selected state and city to get cleared. When we change state drop down we need previously selected cities to get cleared.

You should now be good to go. Enjoy cascading drop down.



Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com