-
Notifications
You must be signed in to change notification settings - Fork 9
Description
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; },
_UnderlyingArrayis initialized as an array, not a set. - Other Methods:
AddByIdandGetByIdcorrectly 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
_UnderlyingSetis 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:
- Initialize an uploader instance.
- Bind inputs using
Uploader.Inputs.AddById. - 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.