Uploaded image for project: 'Pluto'
  1. Pluto
  2. PLUTO-575

Javascript fails to correctly clear out select boxes

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 2.0.0
    • 2.0.2, 2.1.0
    • portlets-admin
    • None
    • Windows/Mac IE and Firefox were tested.

    Description

      The javascript functions that are called when the value of the page select box and the portlet select box are changed fail to correctly clear out the options presented to the user. This can result in trying to add a portlet that doesn't exist for the specified context, or the user may try to remove a portlet from a page that doesn't actually contain that portlet.

      The problem stems from two issues in the following code:
      for(var i = 0; i < portletsSelectBox.options.length;i++) {
      portletsSelectBox.options[i] = null;
      }

      1: As the loop executes, the value of portletsSelectBox.options.length goes down, so the loop does not execute the correct number of times. This results in some elements not being deleted.
      2: Each time an option is removed from the portletsSelectBox.options, the entire array is reindexed. So if you delete the element at positon 0, the item in position 1 moves to location 0. This results in this item never being deleted.

      These errors occur on both the select box for the pages and the box for the portlets. In each instance, the error may be fixed through the use of a while loop as demonstrated below.

      In function <portlet:namespace/>doSwitchPage(select), replace the following code:
      for(var i=0; i < placePortletsSelect.options.length;i++) {
      placePortletsSelect.options[i] = null;
      }

      with this code:
      while (placePortletsSelect.options.length > 0) {
      placePortletsSelect.options[0] = null;
      }

      And in function <portlet:namespace/>doSwitch(select), replace the following code:
      for(var i = 0; i < portletsSelectBox.options.length;i++) {
      portletsSelectBox.options[i] = null;
      }

      with this code:
      while (portletsSelectBox.options.length > 0) {
      portletsSelectBox.options[0] = null;
      }

      Attachments

        Activity

          People

            ate Ate Douma
            allanj37 Allan Jackson
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 1h
                1h
                Remaining:
                Remaining Estimate - 1h
                1h
                Logged:
                Time Spent - Not Specified
                Not Specified