Client-side remove row

Feb 21, 2011 at 4:15 PM

How would I go about removing a row from the file list client-side?  I currently have a js function to get the filename and remove the element, but if you click upload, the file will still be posted.  My goal is to have a client-side function to check the filename when the file is added to the list to determine if the filename is valid according to some requirements I have.  If it's invalid, it should be removed from the upload queue.

Here's my current function:

function GenerateFileRow(uploader, row, container) {
   Flajaxian.generateFileRow(uploader, row, container);

   //get filename for this row
   var rowText = document.getElementById(uploader.get_id() + "_FileBoxFileListRowText_" + row.id).innerHTML;

   //if the filename is invalid, remove it from the list and notify user
   if (rowText == "test.zip") {
      var element = document.getElementById(uploader.get_id() + "_FileBoxFileListRow_" + row.id);
      
      //this line removes the element from the display, but apparently the file is still in the queue
      Flajaxian.removeChildren(element);
                
      alert("File: " + rowText + " is invalid.");
   }
}

Feb 22, 2011 at 8:10 PM

I've come up with a solution.  This will successfully remove the item from the queue list client-side.

function GenerateFileRow(uploader, row, container) {
   Flajaxian.generateFileRow(uploader, row, container);

   //get filename for this row
   var rowText = $.trim(row.textUI.innerHTML);

   //if the filename is invalid, remove it from the list and notify user
   if (rowText == "test.zip") {
      var file = uploader.getFileInfoByID(row.id);
      if (file) {
         Flajaxian.removeHandler(file.btnUI, 'click', Flajaxian.bind(uploader._cancelFileClicked, uploader));
         file.ui.style.display = "none";
      }

      uploader._flash.CallFunction("" + uploader._flash_argumentsToXML([row.id], 0) + "");
                
      alert("File: " + rowText + " is invalid.");
   }
}
Apr 13, 2013 at 5:03 AM
nice article, just to point out the CallFunction should be :

uploader._flash.CallFunction("<invoke name=\"fileRemoved\" returntype=\"javascript\">" + uploader._flash_argumentsToXML([row.id], 0) + "</invoke>");