0 Replies Latest reply on Jul 27, 2008 2:23 AM by geekkit

    Combobox enable/disable

    geekkit

      So I'm using the Richfaces combobox and I want to have the combobox in the disable state when the page/form is loaded (i.e., onload via some javascript within the head element of the HTML document). I have come up with a rather dirty/ugly hack to make it work by doing the following (assuming my form id is 'formfields' and my combox id is 'stateorprovince'):

      function initAddressFields()
      {
       document.getElementById("formfields:stateorprovincecomboboxField").disabled = true;
       document.getElementById("formfields:stateorprovincecomboboxField").value = "";
       document.getElementById("formfields:stateorprovincecomboBoxButtonBG").disabled = true;
       document.getElementById("formfields:stateorprovincecomboboxButton").disabled = true;
      }
      window.onload = initAddressFields;


      These are of course all of the input elements that are spat out at run time to create a rich:combox (of course there are also a bunch of divs too).

      I've seen examples where the component is referred to within some EL expression within (for example) an h:commandButton but that's not what I want to do. Is there are cleaner way to enable/disable a richfaces combox within some arbitrary javascript snippet? Something like this:

      document.getElementById("formfields:mycombobox").disabled = true;


      I noticed the documentation for Richfaces and it mentions that there is an enable() and disable() function. I tried both of them (even after downloading 3.2.2 - hot off the press!) and tried to say this:


      document.getElementById("formfields:mycombobox").enable();
      ...
      document.getElementById("formfields:mycombobox").enable();


      But found it did nothing (even with 3.2.2 because apparently there was a bug report for 3.2.1 that suggested enable() and disable() did nothing). Any help most appreciated.

      Btw, a couple of things I came across:
      1.) Don't use z-index in your HTML CSS in conjunction with the rich:combobox, it messes up its ability to view the drop down list (actually it hides it underneath).
      2.) don't use position: relative with your HTML CSS inconjunction with the rich:combobox, it offsets the drop down list by several pixels which makes it look buggy