Open jerbaroo opened 7 years ago
A fix for this was not to use UI.valueChange
which uses the DOM keydown
event, but instead use a new event function which uses the DOM change
event:
...
on change input $ const $ do
liftIO $ handler "File selected."
-- |change event.
change :: Element -> Event ()
change = void . domEvent "change"
The documentation for the DOM change
event is very similar to that of UI.valueChange
:
UI.valueChange
:
Event that occurs when the user changes the value of the input element.
change
:
The change event is fired for \, \
The main reason why I used the keypress
event was that this makes sure that the user is the one who did the change. (This is relevant for a smooth FRP experience.) The documentation you mention indicates that the change
event ensures the same thing, and I'm inclined to use it in the implementation of valueChange
.
However: Do browser really follow this specification, or do they also emit a change
event when the contents of the DOM element was changed programmatically, e.g. with input.val('foo')
(in jQuery notation)? The latter would be undesirable.
I ran into this (or similar) problem when I wanted to use sliders (input type = range) as input.
https://gitlab.imn.htwk-leipzig.de/waldmann/matrix-game/blob/master/src/Main.hs#L101
@maweki solved it with onDomEvent "input"
. This is currently is not exported?
Here is the code for the problem described below.
Problem
text
of thediv
is"No file selected."
.input
and select a file.text
of thediv
not change.text
of thediv
change to"File selected."
. (Chrome only)button
instead ofinput
, by using the commented line, and the problem is the same.Reproduce
git clone https://github.com/barischj/threepenny-slow-valuechange
cd threepenny-slow-valuechange
stack setup && stack build && stack exec threepenny-slow-frp-exe
System
Additional notes:
text
of thediv
won't update even after pressing ESC.