Back to Writing

Get FileList from DHTMLX Form item type File

How to access the FileList from a DHTMLX Form item type File for AJAX file uploads.

Eli Geske 1 min read
dhtmlx form file FileList upload

The DHTMLX Form item type of File creates the html element type of file. For some reason DHTMLX’s documentation now has this set as “Deprecated”. But if you are still using this and need to get the FileList from the input to do an AJAX form post for file upload this is a quick script to use.

Requirements:

  • DHTMLX Form
  • jQuery

Just after loading the dhtmlx library code add this to create a new method in the Form class.

dhtmlXForm.prototype.getItemFileList = function (name) {
  return $(this.cont).find("[name='" + name + "']")[0].files
}

Usage example:

dhtmlxEvent(window, 'load', function () {
  var layout = new dhtmlXLayoutObject(document.body, '1C')
  formData = [{ type: 'file', name: 'myFile' }]
  myForm = layout.cells('a').attachForm(formData)

  console.log(myForm.getItemFileList('myFile'))
})