I'm having some issues working with controlled inputs in Rum where the cursor position jumps to the end of the text while typing. This makes it difficult to type in the middle of a text. I have tried to find the minimal case where it happens:
(def a* (atom ""))
(defn field-without-on-change
[a]
[:input {:value a}])
(rum/defc form-with-on-change < rum/reactive
[]
[:form {:on-change #(reset! a* (-> % .-target .-value))}
(field-without-on-change (rum/react a*))])
However, putting the :on-change
attribute on the input-tag works:
(def a* (atom ""))
(defn field-with-on-change
[a]
[:input {:on-change #(reset! a* (-> % .-target .-value))
:value a}])
(rum/defc form-without-on-change < rum/reactive
[]
[:form {}
(field-with-on-change (rum/react a*))])
Thanks for the response, sorry for the delay 🕕
So the on-change handler has to be put directly on the :input
tag; putting it on the :form
tag won't work.
if form's on-change
is not called when input value is changed by user then yes
The form's :on-change
is called when the input value changes, updating the atom causing the input to change – this is working fine. But it also resets the cursor position to the end of the text which is a problem :thinking_face:
It only resets the cursor position when the :on-change
handler is put on the form
-tag. There are no issues when putting it on the input
-tag.
I tried posting a gif in this thread that illustrates the issue, but I'm not sure it was uploaded correctly edit: here it is: https://user-images.githubusercontent.com/15210698/52402545-d6f75200-2ac4-11e9-9703-ef23acb38846.gif
you should render input value from some data and change this data in on-change
https://github.com/tonsky/rum/blob/gh-pages/examples/rum/examples/inputs.cljc