Skip to content

Conversation

gazpachoking
Copy link
Contributor

If you bind a signal to a file input, and also have a change/input listener on that input, the event handler will get called before the signal has been updated with the new data. From this thread

The following will log 'undefined' the first time the change event is fired, and be one change behind for subsequent events.

<input type="file" data-bind-file data-on-change="console.log($fileNames[0])">

This fixes that by stopping the propagation of the event in the bind handler and re-dispatching it once the signal has been updated. Feels hacky though.

},
),
)
target.dispatchEvent(new CustomEvent(evt.type, {detail: true}))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, maybe this should go in a finally so the event doesn't get swallowed in case there is an error reading the files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant