Join Gini von Courter for an in-depth discussion in this video Using option buttons, part of InfoPath 2010 Essential Training.
Just as check boxes are the best control in a universe of only two choices, option buttons are the best control in a universe of three or four or perhaps five choices, where a user can only choose one item. Option buttons then are an alternative to dropdown lists, and option buttons present clear choices, unambiguous choices, that you can easily see on the form, so the option buttons give users a choice to kind of rock back and say, which of those choices do I want? We are going to create some option buttons here for the posttype.
There are four specific choices that a user has here. They can say please post only the description that I sent. The second choice is post a description with a link to a file that I have attached. The third choice is post this description along with the contents of the file on the page. And the fourth choice is post this description with a link to somewhere else on the site. For example, that fourth choice might be I want to post an announcement and point people back to another section of the site.
So, posttype is going to go right here. Let's go ahead and drop in option buttons. It's important that I know that there are four options, because the moment I choose the option button control, I'm asked how many option buttons there will be altogether. Up until now, InfoPath has been fairly forgiving. If we insert a control and we want to move it, or change our minds about it, it's pretty easy to modify it, but the number of option buttons is not a property. When we select four option buttons, it will actually create four of them as a set together.
And it's a little bit more difficult to add another option button, not impossible, but it's just a little harder. So, rather than choosing some number randomly, find out how many choices you have first. Here are my four option buttons and again, they're bound to this new field that was put in, field3. But I actually need them to be bound to posttype, so I'm going to right-click and change their binding. And I am going to do this four times.
Now, it helps if I just click on each point to them and see, there we go. They are all bound to the right control. I can get rid of field3. All good. I need to enter text, and I have my four choices. I can either add them in some kind of alphabetical order, although they all start the same way, or in this case I'm going to put the option that I believe is the default option at the top, so Description only, and I can just arrow down. In this case if I press Enter, it actually creates some space, so I don't want to do that.
And Description with link to file, Description with file content, and finally, Description with URL link. We'll have to find a way to capture that later, which we'll do. I'd like to make a little more space for this. I am simply going to slide this over because we have a lot of room because this Check Box control doesn't take up much space at all. Let's now take a look at the properties of option buttons.
You'll note that each option button has a value when it's selected. This one, for example, is the first option button, and its value is 1. The second option button's value, not surprisingly, is going to be two, and just trust me that the next two are going to say three and four. Now, you might want to use those numbers to do specific actions. You might, for example, need to use them in a calculation. But if you don't, you should change these values so that they make sense, when you do something like see this data with simply a heading at the top.
Because if the heading said posttype and all we stored in terms of data or passed along was one, two, three or four, somebody at the other end, in the Office of Electronic Services, needs a little sticky note that tells them what one means, or two. And we can so easily go in and simply say that when someone selected one that they want to have the description only. And I can even use probably some pretty decent shorthand here because the people who are reading this know that they're looking for a posttype. So like this can say Desc/file link, and I'm just going to come up with a charming description for each one of these that will make some sense downstream: Desc/file content and then Desc/URL.
If I wanted to put all the text in there, it wouldn't hurt for me to do that. And I could copy/paste the text from here into here. Now there's one other property that I have, and that's that one of the buttons is selected by default. Let's slide over and preview what this section of our form looks like real quickly. Right now, no button is selected, and so if I click, it chooses whatever item I click, and when I choose a different option button, the first one is unselected.
That's how option buttons work. I can only choose one. So, let's go ahead and make this very first choice our default. Change its properties. This button is selected by default, Description only. If I apply it, I can actually see it there and say OK. So a small universe of choices, but a total universe. These are the four things that we'll do as a result of having received this particular post information.
I think this looks great. Don't be afraid to use option buttons any time you have three or more options. If you only have two options, then the choices should more likely be a check box or a dropdown list.
- Creating a template from scratch
- Understanding and modifying data sources
- Formatting a template
- Inserting text controls, data pickers, and check boxes
- Catching incorrect or missing data
- Using tables and sections for repeating data
- Calculating a value with form data
- Checking spelling and testing a template
- Creating views
- Developing data connections to SharePoint lists and XML files
- Understanding publishing options for InfoPath templates
- Importing Excel and Word forms