Selecting "Other" in Drop-Down unhides Text Box

T

Tom

I am a newbie to InfoPath, but experienced writing code with MS-Access (VBA)
and designing forms in it, so that is where my question is coming from.

I was asked to do one of the following:

1) Design an InfoPath form containing a dropdown with values from a
secondary data source but NOT restrict the user to only those values (i.e.
they can add their own values when there is nothing on the "pick list" that
matches their need) as can be done with Access . I read various discussions
where this is difficult without writing one's own control or buying a 3rd
party control. I have ruled out this solution for my task due to time.

OR

2) Provide a dropdown with a list of values and the value "Other" appended
to the end of the list. When the "Other" entry is selected, the user would
have a text box appear that would allow the user to describe the "other"
item.

I know how to attach a static list of values to the drop-down. I think I
know how to get dynamic values from a secondary data source and append the
"Other" entry to the bottom. My data source will either be MS-Access,
SQL-Server, or MS-Excel (Excel is not my choice).

My question:

- Can you point me to something where I can see an example of the following?

1 -- User selects value from drop-down. As long as it is NOT "other", the
value they select populates the drop-down box and the data element in the
primary data source.

2 -- User selects "Other", a hidden text box is "un-hidden" and they are
allowed to describe "other".

Any help you can provide would be appreciated!
 
S

S.Y.M. Wong-A-Ton

Option 1 can be done by using web services or writing code in ADO if you are
using a database. I am currently in the process of writing an article on
exactly how to do this, but then neither with web services nor ADO, but
something else (cannot say what yet due to copyright issues). I'm not sure
when the article will be out, though, since I won't be publishing it on my
own site and am dependent on the publishing schedules of the publisher. But
it is definitely a technique worth trying out.

Option 2 is also possible, but wouldn't you be limited to only 1 extra value
then? Or perhaps I understood your explanation on how you'd want to do this
incorrectly? Also, how would you want to write the changes back to the
secondary data source? I think you'll pretty much wind up doing the same as
in option 1 if you want the changes made to the secondary data source to be
permanent.

My question to you is: Do you have a web server available? If so, try
writing a web service to do the update to the underlying source of the
secondary data source.

As a side note: There is a new combo box control in InfoPath 2007 that
allows you to type text into it for a new item. You'd only need to take care
of the update of the secondary data source then...
 
T

Tom

Thank you for your reply!

Let me give you some of my constraints:

- I am limited to InfoPath 2003 for the time being. My employer has not
committed to the upgrade. Not sure if they will. They need to be convinced
that InfoPath is the right tool for these type things, so I have to find
work-arounds for the time being.

- Also, for the time being, I don't have a web service available for this.
Again, I have to convince them that InfoPath is the solution for them. I am
currently restricted to online data entry, minor secondary data sources,
electronic filing of the .XML file (as is) and paper print out. They want to
use InfoPath as a central repository for getting the form, not using it to
feed a database. I need to prove its worth, then they may allow me to take it
a step further.

As was the case when I was programming MS-Access applications in a
spreadsheet user community, the organization is only thinking "fillable"
templates that can be printed. I suggested using Acrobat or MS-Word (which
they already have,) but they wanted to try InfoPath (I think a good choice)
but are not willing to commit to going the next step until I prove its worth.

On Option 2, they are only thinking that another "box" should be there to
allow one to type in a value if "other" is chosen ... the old paper "fill out
a form" paradigm. If I can pull this off, then I may have the credibility to
go the routes you suggested ... my preference.

Any thoughts on how I can make this work? I am familiar with events, but not
the ones in InfoPath. I don't know if it has the equivalent of "AfterUpdate"
that I had in Access with comboboxes and writing VBA.

Could you point me to an example that:

- shows the correct event to use (equivalent of AfterUpdate)
- how to evaluate the entered value, and
- how to change the visibility of a control

I have not started programming InfoPath yet. To date, I have just been
working through how to "tame" the UI. I just need a little "jump start".

Thank you ahead of time for any help you can provide!
 
S

S.Y.M. Wong-A-Ton

To answer your questions:

- shows the correct event to use (equivalent of AfterUpdate)
You can use the OnAfterChange event
(http://msdn.microsoft.com/library/en-us/ipsdk/html/xdevtOnAfterChange_HV01021366.asp?frame=true)
for this, but I would recommend using conditional formatting for the hiding
and showing; not code.

- how to evaluate the entered value, and
You can retrieve the value of the drop-down through code using

XDocument.DOM.selectSingleNode("XPath_to_dd_field").text;

This will give you the value of the selected item in the drop-down list box.
If using conditional formatting (which is what I'd suggest) on the text box,
when setting up the condition to show/hide the text box, you can just select
the field on the InfoPath form that represents the drop-down and compare it
(you will be comparing its value) to the value you assigned to the "Other"
item in the drop-down list box and then hide/show the text box based on the
result of this evaluation.

- how to change the visibility of a control
Look into using conditional formatting on the text box. Double-click on it
to open its Properties dialog box. On the "Display" tab you will see a button
that says "Conditional Formatting". With this you can set up formatting of
the text box, i.e. show/hide it in your case, based on a certain condition.
Check the InfoPath help file if you need more information on this.
 
T

Tom

Thanks for your help!

S.Y.M. Wong-A-Ton said:
To answer your questions:

- shows the correct event to use (equivalent of AfterUpdate)
You can use the OnAfterChange event
(http://msdn.microsoft.com/library/en-us/ipsdk/html/xdevtOnAfterChange_HV01021366.asp?frame=true)
for this, but I would recommend using conditional formatting for the hiding
and showing; not code.

- how to evaluate the entered value, and
You can retrieve the value of the drop-down through code using

XDocument.DOM.selectSingleNode("XPath_to_dd_field").text;

This will give you the value of the selected item in the drop-down list box.
If using conditional formatting (which is what I'd suggest) on the text box,
when setting up the condition to show/hide the text box, you can just select
the field on the InfoPath form that represents the drop-down and compare it
(you will be comparing its value) to the value you assigned to the "Other"
item in the drop-down list box and then hide/show the text box based on the
result of this evaluation.

- how to change the visibility of a control
Look into using conditional formatting on the text box. Double-click on it
to open its Properties dialog box. On the "Display" tab you will see a button
that says "Conditional Formatting". With this you can set up formatting of
the text box, i.e. show/hide it in your case, based on a certain condition.
Check the InfoPath help file if you need more information on this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top