I'm playing around with the re-frame
framework.
In the code below, I am having trouble with updating the input value when the user types something in:
(defn measurement-input [{:keys [amount unit path]}]
(let [amt (atom amount)]
(fn []
[:div
[:input {:type "text"
:value @amt
:on-change #(reset! amt (-> % .-target .-value))}]
[:input {:type "button"
:value unit}]])))
The input value will not change until until I change :value
to :defaultValue
. I am pretty sure the above example closely mirrors Reagent
's input example.
In the code below, I am trying to do two things when the user updates the input value. I'm trying to reset!
the input's value as well as dispatch
the value to an event handler. I've wrapped up both of these function calls in a do
call.
Also of note is that in the code below, the user is able to update the value in the text field.
(defn measurement-input [{:keys [amount unit path]}]
(let [amt (atom amount)]
(fn []
[:div
[:input {:type "text"
:value @amt
:on-change (do #(reset! amt (-> % .-target .-value))
(re-frame/dispatch [:update-value @amt]))}]
[:input {:type "button"
:value unit}]])))
In the javascript console, I get the following error:
Uncaught TypeError: Cannot read property 'call' of null template.cljs?rel=1435381284083:101
Any help is appreciated everybody!