Skip to content

Bug: Uploader.Inputs.RemoveById(sElementId) attempts removal from _UnderlyingSet instead of _UnderlyingArray #8

@OlufNielsen

Description

@OlufNielsen

Title:

Bug: Uploader.Inputs.RemoveById(sElementId) attempts removal from _UnderlyingSet instead of _UnderlyingArray

Description:

I encountered a bug when calling the RemoveById method on the Uploader.Inputs class to remove an input by ID. The function is designed to operate on a data structure _UnderlyingSet, but the class uses _UnderlyingArray for its other operations.

Code Details:

The RemoveById function implementation is as follows:

/**
 * Remove HTML element from input Controls by id.
 * @api
 * @param {string} sElementId Id of HTML element.
 */
RemoveById: function(sElementId) {
    var oInput = this.GetById(sElementId);
    if (oInput) {
        delete this._UnderlyingSet[sElementId];
        this._RaiseOnCollectionChanged([], [oInput]);
    }
},

However, in the Uploader.Inputs class:

  • Initialization:
    constructor: function(oUploader) {
        this._UnderlyingArray = [];
        this._Uploader = oUploader;
    },
    _UnderlyingArray is initialized as an array, not a set.
  • Other Methods:
    • AddById and GetById correctly reference _UnderlyingArray:
      AddById: function(sElementId) {
          var oInput = new ITHit.WebDAV.Client.Upload.Controls.Input(sElementId);
          this._UnderlyingArray[sElementId] = oInput;
          this._RaiseOnCollectionChanged([oInput], []);
          return oInput;
      },
      
      GetById: function(sElementId) {
          return this._UnderlyingArray[sElementId];
      },
    • The _UnderlyingSet is not initialized anywhere in the constructor, leading to the following declaration:
      /**
       * @private
       * @type {Object.<string, ITHit.WebDAV.Client.Upload.Controls.Input>}
       */
      _UnderlyingSet: null,

Error Details:

The bug throws this error:

ITHitWebDAVClient.js:22956 Uncaught TypeError: Cannot convert undefined or null to object
    at childClass.RemoveById (ITHitWebDAVClient.js:22956:48)
    at HTMLButtonElement.<anonymous> (main.ts:113:46)

Possible Fix:

Change RemoveById to correctly reference _UnderlyingArray instead of _UnderlyingSet:

RemoveById: function(sElementId) {
    var oInput = this.GetById(sElementId);
    if (oInput) {
        delete this._UnderlyingArray[sElementId];
        this._RaiseOnCollectionChanged([], [oInput]);
    }
},

Additional Context:

The DropZoneCollection class uses _UnderlyingSet consistently for similar operations, which suggests that the issue in Inputs might stem from incomplete refactoring or mismatched design between these two collections.

Steps to Reproduce:

  1. Initialize an uploader instance.
  2. Bind inputs using Uploader.Inputs.AddById.
  3. Attempt to remove an input using Uploader.Inputs.RemoveById.

Expected Behavior:

Inputs should be correctly removed from _UnderlyingArray without errors.

Actual Behavior:

The method references an uninitialized _UnderlyingSet, causing a TypeError.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions