Pode.Web icon indicating copy to clipboard operation
Pode.Web copied to clipboard

Enable events support on File Upload elements

Open Badgerati opened this issue 2 years ago • 0 comments

Currently the File Upload element doesn't allow the binding of events, which means if you render the element outside of a form ... well ... it's pretty useless!!

Ideally we want the following to be possible:

$upload = New-PodeWebFileUpload -Name 'File' -Accept '.jpg', '.png' |
    Register-PodeWebEvent -Type Change -ScriptBlock {
        $WebEvent | Out-Default
    }

In order to do this we'll have to remove NoEvents = $true on the element, and then the serialize() function in templates.js will need tweaks to support directly serializing a file element - by adding the following "else if" between the "if" and "else":

else if (this.element.attr('type') === 'file') {
    data = newFormData(this.element);
}

and the PodeFileUpload class will need ${this.events(data.Events)} adding as well.

Note: it's probably worth testing this function probably, as looking over it I don't see how this could work for other input elements directly 🤔

Badgerati avatar Apr 28 '23 20:04 Badgerati