4 Replies Latest reply on Dec 2, 2010 4:35 PM by maniac_coder

    Combobox display refresh help


      Good afternoon everyone! I certainly am hoping that someone can help me out with this particularly thorny problem. I've followed suggestions that I've found here and there, as well as tried many different things on my own, all to no avail.


      The situation is this. I have several different combo boxes that allow selection of a variety of values. Once a value, say "12" is selected in one of the combo boxes, I want to prevent users from selecting it in another box. Note that I don't want to delete the value out of the index of all the other boxes, simply because users change their minds and if they decide that they want "12" in box 3 instead of 1, I don't want to run into a continual index update cycle.


      What I am trying to do, continuing my example, is when a user selects a value in box 2-n, the validation code checks to see if the just-selected value is already found in one of the other boxes. If it is, an alert is generated to the user and the combo box that they just changed is reset to it's former value. The code is all working EXCEPT that the combo box isn't refreshing. In my example, if I select "12" in box 1, select "27" in box 2, enter some data elswhere, then select "12" in box 2, I get a pop-up just like I want. The 2nd box still displays "12", however, which is wrong. When I click into the box, however, "12" disappears and the correct former value ("27" in my example) is displayed. From this I can see that the commit is indeed stopped when the duplicate is detected. The display, however, won't reset.


      I've tried a variety of things -- setting the selectedIndex to a different value and then back, setting the field (event.target.text = strOldValue) and many other tweaks, all without result. Nothing I do seems to reset the value that the user sees until they click into the field.


      Now for the code. This function is called by the validate event associated with each combo box (the variable passed to the function, intNumVariableBoxes, is a global variable containing the total number of combo boxes on the form, allowing me to easily re-use this code on forms with different numbers of combo boxes):


      function fn_validateVariableBoxNumberUnique(intNumVariableBoxes) {
         var re_strNotBlankTest = /^\S+$/;
         var strCurrentFieldName = event.target.name;                       // Grabs name of field being validated
         var strBoxName = "";                                               // Used to store name of field that is checked against
         if (re_strNotBlankTest.test(event.value)) {                        // Box not blank, so we need to check
            for (var i=0; i<intNumVariableBoxes; i++) {
               strBoxName = "other_box_case_number_"+((i<9)?"0":"")+(i+1);  // Derives box field name. Try zero-padded single digits first
               if (!this.getField(strBoxName))
                  strBoxName = "other_box_case_number_"+(i+1);              // Zero-padded single digits didn't work, try regular (we have to do this since some forms use zero-padding in field names and some don't)
               if ((strBoxName != strCurrentFieldName) && (this.getField(strBoxName).value == event.value)) {
                  app.alert("Box number "+event.value+" already selected in field ["+strBoxName+"].\nPlease double-check your selection.");
                  event.rc = false;                           // Set to false so that value doesn't commit
                  return false;
               } // end IF box value found in another box
             } // end FOR loop to cycle through variable boxes
          } // end IF check that current field value != empty
         return true;
      } // END FUNCTION fn_validateVariableBoxNumberUnique


      I'm at my wits end on this one and don't know what else to try to get the combo box to refresh. Any help or pointers are greatly appreciated.