9 Replies Latest reply: Aug 14, 2012 3:11 PM by Arie Geller RSS

    Apex 3.0 : use cascading lovs

    829948
      Hi,

      I have a first lov (Displays description, returns key value). I want that my second lov depends of the value selected by the first lov.
      I have tried to use the event "onchange" on the first lov in order to call an Ajax function but the event "onchange" doesn't work. Even a simple "alert" is not displayed.

      I have read that this event couldn't work because the input field is disabled. Is it the reason ?

      I work on Apex 3.0.1.00.07 (I can't upgrade for now). On another project, I work on Apex 3.2.1.00.12 and the solution using the "onchange" event works. Indeed, If I test the same application on Apex 3.2.1.00.12, it works.
      Oracle Database : 10.2.0.5

      The LOV generated on Apex 3.0.1 is :
      <span class="lov">
      <input type="text" name="p_t03" size="30" maxlength="2000" value="" id="P1_PROJET" onchange="maj_SB();" disabled="disabled" onfocus="this.blur()" />
      <a  href="javascript:genList0_p_t03_2()"><img src="/i/list_gray.gif" width="13" height="13" alt="Popup Lov" /></a>
      </span>
      The LOV generated on Apex 3.2 is :
      <fieldset class="lov" id="P1_PROJET_fieldset">
      <table summary="" border="0" cellpadding="0" cellspacing="0" class="lov" id="P1_PROJET_holder">
      <tr><td  class="lov">
      <input type="text" name="p_t03" size="30" maxlength="2000" value="" id="P1_PROJET" onchange="maj_SB();" disabled="disabled" onfocus="this.blur()" />
      </td><td>
      <a  href="javascript:genList0_p_t03_2()"><img src="/i/list_gray.gif" width="13" height="13" alt="Popup Lov" /></a>
      </td></tr></table></fieldset>
      The maj_SB function is only called with Apex 3.2. Is there a way to solve this problem ?

      Thank you.
      Regards,
      David
        • 1. Re: Apex 3.0 : use cascading lovs
          Arie Geller
          Hello David,

          >> I have tried to use the event "onchange" on the first lov in order to call an Ajax function but the event "onchange" doesn't work.

          When you are using JavaScript to set the value of an item programmatically – as all the popup items do - the onchange event is not fired by the browser and you need to do it manually. This manual action was only added to the code in APEX 3.1. As you are using a previous version, the onchange event will not work for you.

          As you can’t upgrade the APEX version, you need to rely on a different event, for example, the onblur event. It will fire your AJAX call each time the user will leave the first field, regardless of his/her action (i.e. even if the value of the first field was not changed), but at least it will allow the functionality you want to achieve.

          Depends on the “cost” of your AJAX call, you can implement your own item-value-change check before invoking the AJAX call.

          Regards,
          Arie.

          -------------------------------------------------------
          &diams; Please remember to mark appropriate posts as correct/helpful. For the long run, it will benefit us all.

          &diams; Author of Oracle Application Express 3.2 – The Essentials and More
          • 2. Re: Apex 3.0 : use cascading lovs
            829948
            Hi Arie,

            Thank you for your clear answer.

            I still have some questions :

            _ Are you sure that I can fire the "onblur" event even if the input field is disabled ?
            _ My goal is just that the second popup lov depends on the first one. So maybe I will do that with Ajax or maybe I will just call the "doSubmit" function. How can I implement my own item-value-change check ?

            Regards,
            David
            • 3. Re: Apex 3.0 : use cascading lovs
              Arie Geller
              Hello David,

              First, as you already revealed your first name, please change your forum handle to something friendlier than User123… It’s easier for us this way.

              >> Are you sure that I can fire the "onblur" event even if the input field is disabled ?

              Well, as you are using the “lov (Displays description, returns key value)” item, the display part is indeed disabled, so the onblur event will not be fired.

              As your second (dependable) item is also a LOV item, it seems that the easiest way to implement the cascading effect is to submit the page after the first selection.

              >> How can I implement my own item-value-change check ?

              If you are choosing to submit the page after the first LOV selection, this issue is not relevant, as the APEX engine will build the second LOV based on the first one.

              If you choose to use AJAX, you can define a hidden item and populate it with the value of the first LOV. When calling the AJAX function – after the user “visited” the first LOV item, you can simply compare the current value of the first LOV item with the value of the hidden item, and invoke the AJAX call only if they are different.

              Regards,
              Arie.

              -------------------------------------------------------
              &diams; Please remember to mark appropriate posts as correct/helpful. For the long run, it will benefit us all.

              &diams; Author of Oracle Application Express 3.2 – The Essentials and More
              • 4. Re: Apex 3.0 : use cascading lovs
                829948
                Hi Arie,

                I have changed my forum handle.

                I see how to use Ajax with the hidden item but the problem will still the same for me : I can't detect when the user has "visited" the first LOV item.

                Regards,
                David
                • 5. Re: Apex 3.0 : use cascading lovs
                  Arie Geller
                  Hi David,

                  >> I can't detect when the user has "visited" the first LOV item.

                  With the specific type of item you have chosen to use there is indeed a problem of detecting value changes. So, let’s take a step back, and let me ask you why you chose this particular type of item. Is there so many selected options to begin with (more than a 100)? Can’t you use, for example, a select list? It will make things much simpler, especially with the version you are using.

                  Regards,
                  Arie.

                  -------------------------------------------------------
                  &diams; Please remember to mark appropriate posts as correct/helpful. For the long run, it will benefit us all.

                  &diams; Author of Oracle Application Express 3.2 – The Essentials and More
                  • 6. Re: Apex 3.0 : use cascading lovs
                    829948
                    Hi Arie,

                    I have a first region in which the user selects some values. Then he press a button and, after submitting, a report is displayed using values choosen.

                    The user has to select two values. The first lov (or any type of item) has to propose more than 1000 values. The second one has to propose many values too and I want that this second lov offers some values using the first one.

                    I think a select list is not appropriated because there are so many values. Maybe there is another type of item but I didn't find it.

                    Regards,
                    David
                    • 7. Re: Apex 3.0 : use cascading lovs
                      Arie Geller
                      Hi David,

                      >> The first lov (or any type of item) has to propose more than 1000 values

                      A select list item will not deal efficiently with 1000 options, so in this case a popup LOV seems like the right choice. However, personally, I don’t believe it is efficient to allow the user to choose over 1000 options. It can be very confusing and time-consuming for the user to pinpoint the desired option. When the users make their choice, do they employ some (off-screen) filters? Maybe you can use this/these filter(s) to reduce the selectable options? What I mean is that instead of having only two components (i.e. items) in your cascading scheme, you can use three?

                      Without more specific details about the nature of your data, it is hard to give you a solid advice on how to design your input. However, given the APEX version you are using, and the issues accompany its popup LOVs, I believe you need to devise an input strategy that doesn’t involve popup LOVs. In order for you to be able to use a select list (which is usually the best item type for cascading items) you need to classify your options into smaller categories (filters) that will include about 100-150 options each. Can you do that?

                      Regards,
                      Arie.

                      -------------------------------------------------------
                      &diams; Please remember to mark appropriate posts as correct/helpful. For the long run, it will benefit us all.

                      &diams; Author of Oracle Application Express 3.2 – The Essentials and More
                      • 8. Re: Apex 3.0 : use cascading lovs
                        829948
                        Hi Arie,

                        I'm working on a e-business context so there is a lot of data.
                        I think that I have found a solution. I have modified the template named "popup LOV" by adding an onclick event on the icon. So when the user click on the icon, my javascript function is called and then a ajax function well populates an hidden field.
                        Then the popup is opened and, since that the select depends of the hidden field, my list is ok.

                        The only negative point is that there only one template "Popup LOV" so If i create a new popup LOV my javascript function will be called.

                        Do you think this solution is ok ? Thank you for your help.

                        Regards,
                        David
                        • 9. Re: Apex 3.0 : use cascading lovs
                          Arie Geller
                          Hello Danny,

                          >> I'm working on a e-business context so there is a lot of data.

                          The problem is not with the size of your data, but more with how you choose to organize it. For example, you may choose to have only one level of hierarchy in your bill of materials, which can lead to very large result sets, or you can have more levels, each leads to a higher resolution in your search filters. Anyway, data modeling is a different issue.

                          >> The only negative point is that there only one template "Popup LOV" so If i create a new popup LOV my javascript function will be called.

                          Yes, one Popup LOV template is an APEX limitation, and that is why I didn’t consider it, until now. Still (and I can’t test it now) you may be able to use the APP_PAGE_ID substitution string (which holds the current application page number) as a parameter in your onclick JavaScript function, which can include a switch statement that can invoke variety of other JavaScript functions, each dedicated to a different calling page. However, this will not resolve the case where you have more than on Popup LOV item on the same page (unless in all the other cases/pages you are not invoking an onclick event).

                          Regards,
                          Arie.

                          -------------------------------------------------------
                          &diams; Please remember to mark appropriate posts as correct/helpful. For the long run, it will benefit us all.

                          &diams; Author of Oracle Application Express 3.2 – The Essentials and More