xdExtension and Conditional Display

E

egrigg9000

Hello,

I am attempting to follow the advice in this posting:
http://groups-beta.google.com/group...3d91c07?q=xdExtension&rnum=5#5966ae9613d91c07

In the repeating group below, there will be one line for each item we
are tracking. I am working on the template. Only some cases will
require comments to be filled out, so it's not worth taking up the
pixels for a text field for every line. The "Enter Comments" button
I have pulling up a javascript dialog which returns a value to the
Comments node for the line it was accessed. Which is cool and works.

I would only like the "Enter Comments" button to show up if the
line in the repeating group is selected.

Right now the behavior is, the "Enter Comments" button does not
show up even though the line is selected.

Can anyone help? I have pasted the code below.

Thanks in advance,

- Elizabeth Grigg
egrigg9000 at yahoo dot com

The data structure is:
<root>
<items>
<StandardItem> //this is bound to the repeating table
<Item Number/>
<Item Title />
<Compliant Percentage />
<Comments /> //this is bound to the button below
close tags etc.

The table layout is:
REPEATING TABLE
ITEM NUMBER | ITEM TITLE | COMPLIANT PERCENTAGE | COMMENTS
___________ __________ ____________________ _________
Textbox | Textbox | Dropdown List | "Enter Comments"
button

The conditional formatting for the Enter Comments button is:
"not(xdExtension:get-fDisplayComments())"
The button is default set to HIDE.

The code:
//Note there is logic in here to turn OFF the button in the row
selected previously. It occurs before the turn ON button logic to
handle the case where the user is clicking on the same location.
//I have traced this code and determined that the helper function is
called, including the ForceUpdate line, but to no visible effect on the
button.

//EG Place for Globals
var fDisplayComments = false;
var sPrevNodeName = "";
//EG End Globals

//EG Helper Functions
//EG HF1 This HF changes the visibility of the comments button
function SetCommentsVisibility(fCommentsVisible)
{
fDisplayComments = fCommentsVisible;
XDocument.View.ForceUpdate();
}
//EG End Helper Functions

//... not including empty functions for other events

function XDocument::OnContextChange(eventObj)
{

if (eventObj.Type == "ContextNode")
{

//don't do anything if the contextchange is away from the object,
such as user clicking outside the repeating group
if (sPrevNodeName != "my:StandardItems")
{
// Selection or context in the form has changed. Write your
code here to respond to the changes.
var objNode;

//Handler for previous node to turn off the button
if (sPrevNodeName != "")
{
objNode = XDocument.DOM.selectSingleNode("//" +
sPrevNodeName);
SetCommentsVisibility(false);
}//end if ""

//Handler for current node to turn on the button
objNode =
eventObj.Context.selectSingleNode("parent::*").nodeName;
SetCommentsVisibility(true);
//Establishment of current node as previous for next time
sPrevNodeName =
eventObj.Context.selectSingleNode("parent::*").nodeName;

}//end if StandardItems
return;
}//end if ContextNode

}

Thanks everyone!

Best,

- EG

P.S. Not sure what protocol is with code snippets, you might want to
paste into Notepad in order to see minus the carriage returns.
 
E

egrigg9000

Hi Renee, Thanks for writing. I am sorry to have to ask for more
information, but this is a long webcast, and from the description it is
hard for me to tell exactly what areas will specifically reference the
type of code I am trying to do with conditional display and
xdExtension. I will nevertheless watch the whole thing if I don't hear
from you and perhaps I will learn something, even if off-topic. Here is
the description: "Interested in learning more about the new Microsoft®
Office InfoPath™ 2003 features for script-less, rapid development?
This session will show how you can take advantage of declarative
business logic features such as rules and actions, roles identity,
advanced controls like file attachments, master-detail, and filtering.
There is also built-in support for calculations to build advanced and
dynamic solutions. Finally, learn how to use e-mail deployment to
deliver InfoPath solutions that allow you to easily gather data from
your users." The part that makes me especially skeptical is the word
script-less. Do you think I should be doing this another way? I'd love
to hear your thoughts.

If anyone else has the time to look at the specific way I am using
xdExtension, I would be very interested in making this solution work in
lieu of any other information. Thanks in advance for your help. I will
keep posted if the webcast is fruitful.

- EG
 
R

Renee in Juneau

I read your post again (with an eye toward your objective rather than
your method) and actually, the way I would implement what you're
talking about *is* scriptless and doesn't involve buttons.

Encase the comment field within an optional section (with the tag,
"add comment" or perhaps just "comment").

If necessary, this optional section would be placed within a cell of
the repeating section so that it's got the proper page placement.

Finally, I would set the comment field's display properties so that it
a) wrapped text and b) expanded to show all text.
 
E

egrigg9000

Just to update everyone. The text I had in the Conditional Formatting
dialog not(xdExtension:get-fDisplayComments()) had a hidden character
in it. That's what happens when you copy/paste from the newsgroup. So
now that's out of there, it works, perhaps too well (see below). Note
that in the dialog there should not be quotes around the expression.

OK, what's wrong now is my code is referencing the entire node to turn
the button on based OnContextChange, rather than turning the button on
for an individually selected row. So, predictably,
SetCommentsVisibility is changing to true for the entire node because
that was the focus set by the last selectSingleNode event.

I never will understand how selectSingleNode can affect what materials
are passed back and forth between functions but we'll leave that for
another day.

The new goal is to change the object for the SetCommentsVisibility
helper app to an item within the repeating group, rather than the
repeating group itself. In other words, this line of code needs to
change:
FROM:
objNode = eventObj.Context.selectSingleNode("parent::*").nodeName;
TO:
objNode =
eventObj.Context.selectSingleNode("parent::*").nodeNameofSelected;
//NOT CORRECT
sPrevNodeIndex =
eventObj.Context.selectSingleNode("parent::*").nodeNameofSelected.Index;
//NOT CORRECT
//the sPrevNodeIndex is a string variable I save for later to make sure
the button goes away for the old selection. In my original code sample
below this is called sPrevNodeName, but I think I will need a unique
index to make this work.

I tried looking at the following msdn article, but it gives the "get"
example in xsl which makes the article worthless to me - this is
JScript. Not sure if I should switch architectures entirely just to
accomodate?
http://msdn.microsoft.com/library/d...html/xdmthGetNamedNodeProperty_HV01103978.asp

I also tried looking at Greg's example which is thorough but also has a
non-scripting architecture. Not sure how the pieces fit together in
that world. However, another vote maybe for changing architecture
completely?
http://www.infopathdev.com/downloads/free/default.aspx?i=cd6b81a217de40a1b249ab42fcff0216

Seems like an architecture change is a lot to ask to get a simple
button to show up.

Anyway, thanks much and crossing fingers somebody has some time out
there.

-EG
 
E

egrigg9000

Thanks Renee!

That was the first thing I tried. It works great, however it did not
pass a peer review. The problems were that with some lines having
comments and some not, having even one comment on one line throws off
the table. The decision was to make comments as a popup so we don't
have to allocate visual space. I have done this work and wasn't nearly
so hard. But there was a side effect of switching to a popup: I said
there would be a comments button now instead of an optional text field,
are we sure we want to look at all those buttons, one for each line?
The answer is: make them show up conditionally on selection.

I was so sure I could do it, that it would be easier than a javascript
popup window, but it looks like I had the difficulty level reversed.

I am working through the webcast that you recommended now. I got a lead
on an Xpath reference called Current(), but I do not know how to
integrate this into the relevant line in my code (the one ending in
nodeName;).

Thanks much, still interested in your advice or anyone else's.

-EG
 
E

egrigg9000

I got some good advice outside this group and want to post the
solution. If anyone wants to elucidate on why this was successful, pls
add to this post. Here is the information that worked for me:

1. Define global variable in the script:
var g_currentPosition = -1;

2. In On context change event, do this:

if (eventObj.Type == "ContextNode")
{
// Selection or context in the form has changed. Write your code
here to respond to the changes.
// reset previous selection
g_currentPosition = -1;

// select the repeating parent node that is currently selected
(group2 should be replaced by the appropriate node)
var node =
eventObj.Context.selectSingleNode("./ancestor-or-self::my:group2");
if (node != null)
{
// get position of currently selected node (again, group2
should be replaced)
g_currentPosition =
node.selectNodes("./preceding-sibling::my:group2").length + 1;
}
XDocument.View.ForceUpdate();
return;
}

3. Set conditional formatting on the button with condition:
"xdExtension:get-g_currentPosition() != position()" and formatting:
"Hide this control"
 

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