Unpopulating a Dropdown list's final selection - InfoPath Dev
in

InfoPath Dev

Unpopulating a Dropdown list's final selection

Last post 08-08-2007 07:15 AM by Aye Caramba. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 08-07-2007 05:06 AM

    Unpopulating a Dropdown list's final selection

    Hi guys - hope you can help me out with some codes.  Here's the situation.  I have a dropdown box and it's list box entries are stored in a separate document.  I have it set up so that when I choose a value (or multiple values), those values populate in a rich-text box (this works perfectly).  That is accomplished by the Data Validation button, then choosing events, OnAfterChange, and then clicking on edit.  This is the code that is being used (it looks different in the Script Editor window, but I think you get my point):

    function msoxd_my_field160::OnAfterChange(eventObj) { // Write code here to restore the global state. if (eventObj.IsUndoRedo) { // An undo or redo operation has occurred and the DOM is read-only. return; } // A field change has occurred and the DOM is writable. Write code here to respond to the changes. if(eventObj.Operation == "Insert") { var objField161 = XDocument.DOM.selectSingleNode("//my:myFields/my:field161"); if(objField161.text == "") { objField161.text = eventObj.Site.text; } else { objField161.text = objField161.text + ", " + eventObj.Site.text; } objField161 = null; }

    What is happening is that when you're in the form and have chosen your value, it's populated in the rich-text box, which is exactly what I want it to do; however, the last value chosen is still ALSO populated in the drop-down box.  So in effect, it shows up twice.  The way I have been able to NOT have the drop down box show the last value chosen is by selecting the very first value in the box, which is blank.  There's got to be a way to tell it that once you tab out of the box, it should NOT show the last value.

    Does that make sense?  Any help with this issue would be greatly appreciated.

  • 08-07-2007 06:32 AM In reply to

    Re: Unpopulating a Dropdown list's final selection

    hi. do you use a multi selectable dropdown list ? not to sure if i really understand your issue but an idea would be that in you onafterchange event use a stringbuilder to concat all you selected values and then on step before writing it into your richtext box cut the last value of the stringbuilder object. you could propably also use just a string, use a delimiter between the different selected values (e.g. "-") and then write something like stringForRichTextBox = mystring.substring(0,mystring.lastindexOf("-")). just a little point on the side i would always use some meaningful names for my controls/nodes because sooner or later it will drive you crazy to work with fieldnames like field17934. does it make any sense ?
    Listen to Motörhead cos they play Rock'n Roll :)
  • 08-07-2007 10:23 AM In reply to

    Re: Unpopulating a Dropdown list's final selection

    Hey nuk -

    1.  "do you use a multi selectable dropdown list ?"

    I don't even know what that is.  I have a list of names (about 100) that are located in a separate xml document.  When you click on the down arrow of the dropdown box, you can choose as many names as you want.  The code I gave above does two things:  a) it put's the values in a rich text box (and doesn't underline them :) ), and b) it lists them in a sentence structure, such as..... XXXXXXXX , XXXXXXXXX, XXXXXXXXX, versus

    XXXXXXX

    XXXXXXX

    XXXXXXX

    It works quite well

    2.  "an idea would be that in you onafterchange event use a stringbuilder to concat all you selected values and then on step before writing it into your richtext box cut the last value of the stringbuilder object. you could propably also use just a string, use a delimiter between the different selected values (e.g. "-") and then write something like stringForRichTextBox = mystring.substring(0,mystring.lastindexOf("-"))."

    Unfortunately, I do not write script.  The one that I showed in my first post was written by someone on this board.  And that script works well - it's just that the last chosen value in the dropdown box is shown IN the dropdown box, while it also populates the rich-text box - so in effect, it shows it twice on my form.

    3.  "just a little point on the side i would always use some meaningful names for my controls/nodes because sooner or later it will drive you crazy to work with fieldnames like field17934. does it make any sense ?"

    Yeah, it makes complete sense? I hear ya bro - I should definately change my control names. 

    Let me know if that makes it more clearer.  Thanks a lot

    And Rock On!

  • 08-07-2007 07:23 PM In reply to

    Re: Unpopulating a Dropdown list's final selection

    Hi Aye,

    Couple simple options:

    1. Hide the dropdown if the value is set. Add a condition to hide the control if it is not blank - this is really easy. You can add a button to show the control again if they have to select it.
    2. Set the value in the dropdown to "" at end of your OnAfterChange routine *and* make sure to add code to the top of the function to exit if the value is blank (so that the other field isn't blanked by the last set).

    Hope that does the trick!

     

    Patrick Halstead
    Project Manager at Qdabra
  • 08-08-2007 07:15 AM In reply to

    Re: Unpopulating a Dropdown list's final selection

    Hi Patrick - thanks a lot for your response.

    Your 1st option worked - however, when I choose just one value, the dropdown box disappears.  I need it to be able to let me choose other values (if need be).  You mentioned that I can add a button to show the control again (I assume to show the dropdown box again??).  How do I do that?  I see that in the controls there is the button control, but it does nothing?

    Your 2nd option I'd rather not do - I might just mess something up inside that Script Editor (and because I do not write code, everytime I go in there it just looks like mumbo jumbo to me).

     Any help with that button issue would be greatly appreciated.  thanks again

    Aye

Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.