Reagent in a modal with a select component

298 views
Skip to first unread message

Jonathon McKitrick

unread,
Jun 30, 2014, 11:47:26 AM6/30/14
to clojur...@googlegroups.com
I am using jQuery and the Bootstrapjs modal to pop up a dialog to edit a row from a table. When the dialog

Here is the code for the component in the dialog:

(defn select-component []
(let [val (atom nil)]
(fn [id choices name-fn value-fn selected-item]
(js/alert (str "Select component " @val " vs " selected-item))
(swap! val #(or % selected-item))
[:div
[:select {:id id
:value @val
:on-change #(reset! val (-> % .-target .-value))}
(for [c choices]
^{:key c}
[option-component (name-fn c) (value-fn c)])]])))

The component needs to do 2 things:

1. Change state when the select is changed (obviously)
2. Reflect the starting value as the selected item when initially rendered

The problem I have is after editing a row where the dialog and select items are correctly populated, editing a second row does not work. The VAL captured by the component closure function already has a value, so the OR expression returns that value, rather than the new one for the new row being edited.

So, is there a way to reset VAL when the component is being rendered with new values?

Jonathon McKitrick

unread,
Jun 30, 2014, 4:26:33 PM6/30/14
to clojur...@googlegroups.com
I ended up setting up another atom to hold the unique id of the record being edited.  When that changes, I reset VAL as well.


--
Jonathon McKitrick



--
Note that posts from new members are moderated - please be patient with your first post.
---
You received this message because you are subscribed to a topic in the Google Groups "ClojureScript" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojurescript/yqDBySfa51Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojurescrip...@googlegroups.com.
To post to this group, send email to clojur...@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.

Reply all
Reply to author
Forward
0 new messages