Pode.Web
Pode.Web copied to clipboard
Enable events support on File Upload elements
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 🤔