Custom generated control disabled

R

Rob Blitz

I had a situation where I needed to populate a dropdown list from two other
date fields to create a list of days between the range specified by those
dates.

My approach to the problem was to create a DOM group with a repeating
element in it. When the date range fields were changed, a Javascript
function runs to populate the repeating element with the list of days within
the range. The next step was to create a drop down list custom control by
modifying the XSLT view file to create a the SELECT tag and the contained
OPTION tags based on the data stored in my repeating element.

My problem is that when I preview the form, the dropdown list populates, but
it's disabled. The only way I can enable it is by removing all of the
special Infopath attributes in the SELECT tag, which is probably not a good
thing, because I won't get the binding I want.

Any ideas?
 
R

Rob Blitz

Thanks Greg,

So if I've understood you correctly, you're advising that I use a secondary
data source that's tied to a script that populates the drop down list. Will
that only work in SP1? I don't recall a way to make a script function the
secondary source, but I'm not using SP1.

Rob


Instead of populating an extra repeating list from script, have you thought
about just populating the drop-down list box itself from script? It sounded
like you didn't really need the extra repeating list, but that you just
created it to help solve your problem. If you just populate the drop-down
list itself, will that work? You just bind it to whatever node you want, but
populate it via script.

I have Examples posted on InfoPathDev that show how to do this. They are:
* Fully Editable Drop-down List Box
* Moving Items Between List Boxes

But all-in-all, if you use a secondary data source (so as to not clutter
your main DOM) that may be the better way to go. If you are using InfoPath
SP-1, you should not need to do any messing with the XSL itself in this
scenario. It should be a matter of binding your drop-down list box to the
correct data node, then telling it to populate from the secondary data
source, which you continue to update via script as you do now.

If you are still having troubles, please give more details.

--
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com



I had a situation where I needed to populate a dropdown list from two other
date fields to create a list of days between the range specified by those
dates.

My approach to the problem was to create a DOM group with a repeating
element in it. When the date range fields were changed, a Javascript
function runs to populate the repeating element with the list of days within
the range. The next step was to create a drop down list custom control by
modifying the XSLT view file to create a the SELECT tag and the contained
OPTION tags based on the data stored in my repeating element.

My problem is that when I preview the form, the dropdown list populates, but
it's disabled. The only way I can enable it is by removing all of the
special Infopath attributes in the SELECT tag, which is probably not a good
thing, because I won't get the binding I want.

Any ideas?
 
R

Rob Blitz

Greg,
I decided to go with the SP1 approach because it seems simpler. However,
I'm having a problem seeing the updates I make to the DOM that I create from
the "support" XML file I added to my solution. I've bound the control to the
repeating node in a defined secondary data source (pointing at the support
XML file) and I've verified that my changes to the DOM are happening inside
the C# code. But when the drop down displays, it's empty. I thought that
perhaps it was due to the fact that the drop down was in a repeating
section, but I tested the same binding on a dropdown that isn't, and it
still didn't pull any data from my secondary DOM.
Do I have to save or commit the changes to the DOM for Infopath to
render the dropdown data?

Thanks again for your help,
Rob


You can access nodes in the secondary data source just as you can in the
main DOM. You would access it by calling:

var oDOM2 = XDocument.GetDOM("Name_of_Secondary_Data_Source");
var oNode = oDOM2.selectSingleNode("XPath_to_Node");

But since you are using V1 and not SP-1 you will not be able to conveniently
bind a drop-down list box to the secondary data source. I was assuming
(sorry) that you were using SP-1. It might be best at this point to just
populate the DOM via script following the examples I listed previously.

--
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com



Thanks Greg,

So if I've understood you correctly, you're advising that I use a secondary
data source that's tied to a script that populates the drop down list. Will
that only work in SP1? I don't recall a way to make a script function the
secondary source, but I'm not using SP1.

Rob


Instead of populating an extra repeating list from script, have you thought
about just populating the drop-down list box itself from script? It sounded
like you didn't really need the extra repeating list, but that you just
created it to help solve your problem. If you just populate the drop-down
list itself, will that work? You just bind it to whatever node you want, but
populate it via script.

I have Examples posted on InfoPathDev that show how to do this. They are:
* Fully Editable Drop-down List Box
* Moving Items Between List Boxes

But all-in-all, if you use a secondary data source (so as to not clutter
your main DOM) that may be the better way to go. If you are using InfoPath
SP-1, you should not need to do any messing with the XSL itself in this
scenario. It should be a matter of binding your drop-down list box to the
correct data node, then telling it to populate from the secondary data
source, which you continue to update via script as you do now.

If you are still having troubles, please give more details.

--
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com



I had a situation where I needed to populate a dropdown list from two other
date fields to create a list of days between the range specified by those
dates.

My approach to the problem was to create a DOM group with a repeating
element in it. When the date range fields were changed, a Javascript
function runs to populate the repeating element with the list of days within
the range. The next step was to create a drop down list custom control by
modifying the XSLT view file to create a the SELECT tag and the contained
OPTION tags based on the data stored in my repeating element.

My problem is that when I preview the form, the dropdown list populates, but
it's disabled. The only way I can enable it is by removing all of the
special Infopath attributes in the SELECT tag, which is probably not a good
thing, because I won't get the binding I want.

Any ideas?
 
R

Rob Blitz

Greg,

Figured it out... when I was creating my secondary DOM nodes I left the
namespace identifier for the main DOM in the third arg of the node
constructor. Setting it to null allowed the DOM to populate properly.

for(DateTime tmpDate = tripFromDate; tmpDate.CompareTo(tripToDate) <= 0;
tmpDate = tmpDate.AddDays(1.0))
{
//this was the problem
//tmpNode =
appDOM.createNode(DOMNodeType.NODE_ELEMENT,"tripDay","http://schemas.microso
ft.com/office/infopath/2003/myXSD/2004-07-07T17:40:36");
//this fixed it
tmpNode = appDOM.createNode(DOMNodeType.NODE_ELEMENT,"tripDay",null);
tmpNode.text = tmpDate.ToShortDateString();
parentNode.appendChild(tmpNode);
}


Thanks for your help with this!

Rob









I just noticed that some of my terminology was incorrect from the previous
posting. The drop-down list box should be "bound" to the main DOM -- because
this is where the value will be stored. But it should be populated by the
secondary DOM. This can be done by double-clicking the drop-down control and
telling it you want it to look up its values in the form's data source, then
choosing a repeating node in your secondary data source.

Having clarified that... first of all, once you make your choice of which
node to bind to, also make sure the the Value and Display Name are pointing
to the correct nodes.

Now, if you need to double check that your code is correctly populating the
support DOM, just drop a Repeating Section With Controls into the view
temporarily, and you will quickly be able to tell whether that worked right.
If it did, and you've verified what I wrote above, then please provide more
details and we'll take it from there.



--
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com



Greg,
I decided to go with the SP1 approach because it seems simpler. However,
I'm having a problem seeing the updates I make to the DOM that I create from
the "support" XML file I added to my solution. I've bound the control to the
repeating node in a defined secondary data source (pointing at the support
XML file) and I've verified that my changes to the DOM are happening inside
the C# code. But when the drop down displays, it's empty. I thought that
perhaps it was due to the fact that the drop down was in a repeating
section, but I tested the same binding on a dropdown that isn't, and it
still didn't pull any data from my secondary DOM.
Do I have to save or commit the changes to the DOM for Infopath to
render the dropdown data?

Thanks again for your help,
Rob


You can access nodes in the secondary data source just as you can in the
main DOM. You would access it by calling:

var oDOM2 = XDocument.GetDOM("Name_of_Secondary_Data_Source");
var oNode = oDOM2.selectSingleNode("XPath_to_Node");

But since you are using V1 and not SP-1 you will not be able to conveniently
bind a drop-down list box to the secondary data source. I was assuming
(sorry) that you were using SP-1. It might be best at this point to just
populate the DOM via script following the examples I listed previously.

--
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com



Thanks Greg,

So if I've understood you correctly, you're advising that I use a secondary
data source that's tied to a script that populates the drop down list. Will
that only work in SP1? I don't recall a way to make a script function the
secondary source, but I'm not using SP1.

Rob


Instead of populating an extra repeating list from script, have you thought
about just populating the drop-down list box itself from script? It sounded
like you didn't really need the extra repeating list, but that you just
created it to help solve your problem. If you just populate the drop-down
list itself, will that work? You just bind it to whatever node you want, but
populate it via script.

I have Examples posted on InfoPathDev that show how to do this. They are:
* Fully Editable Drop-down List Box
* Moving Items Between List Boxes

But all-in-all, if you use a secondary data source (so as to not clutter
your main DOM) that may be the better way to go. If you are using InfoPath
SP-1, you should not need to do any messing with the XSL itself in this
scenario. It should be a matter of binding your drop-down list box to the
correct data node, then telling it to populate from the secondary data
source, which you continue to update via script as you do now.

If you are still having troubles, please give more details.

--
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com



I had a situation where I needed to populate a dropdown list from two other
date fields to create a list of days between the range specified by those
dates.

My approach to the problem was to create a DOM group with a repeating
element in it. When the date range fields were changed, a Javascript
function runs to populate the repeating element with the list of days within
the range. The next step was to create a drop down list custom control by
modifying the XSLT view file to create a the SELECT tag and the contained
OPTION tags based on the data stored in my repeating element.

My problem is that when I preview the form, the dropdown list populates, but
it's disabled. The only way I can enable it is by removing all of the
special Infopath attributes in the SELECT tag, which is probably not a good
thing, because I won't get the binding I want.

Any ideas?
 

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