I try to write a handler for an input type="file" HTML5 element in Nim.
In the HTML I have a Upload button defined as
<input type="file" name="File Upload" id="fileUpload" />
and I set the button's onchange handler to a changed_file function, which I define in Nim as
proc changed_file (event: Event) {.exportc.} =
# Respond to a changed filename
var myfiles = event.target.files
...
but I get a compile error "Error: undeclared field: 'files' for type dom.Node". Obviously the Node type is too generic here. How do I tell Nim that this is a particular node which has a files attribute?
ps: In JavaScript I can just write var file = eventt.target.files[0]; because of its dynamic nature...
type
CustomObj = ref object
files: seq[cstring]
proc changed_file (event: Event) {.exportc.} =
# Respond to a changed filename
var myfiles = cast[CustomObj](event.target).files
...
PS: Dynamic typing is a design bug.
Soo cool! When you know it it seems obvious!
Had a look through the source of the dom module and found a few other gems like newFileReader() and resultAsString - very literally how they translate Nimto JavaScript!