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


On Mon, Jun 30, 2014 at 11:47 AM, Jonathon McKitrick <[email protected]>
wrote:

> 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?
>
> --
> 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
> [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/clojurescript.
>

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.

Reply via email to