Fork me on GitHub

Does anyone have a good example of how to add a form-input into a form based on user-actions?


i.e. User makes a choice on a form -> new field(s) are added to form


I may be being a dreadful n00b, but I can't get my head around it.

Markus Åkerlund Larsson10:02:05

You can just wrap the optional input in an if-expression that checks the value from the other input


I am clearly having a case of the Mondays... Thanks


@c09mld - Of course i have no idea how to get the value from the other input either... I have some code I wrote a couple of months ago I can refer to though...


Yeah, that code is all about extracting the value from an event...


I realise that i have no idea how to interrogate the DOM from inside Reagent... Man i have got to stop adopting tools that I only partly understand based on the apparent utility of a couple of online tutorials... Don't get me wrong I really like what Reagent was able to do for me in terms of getting a very slick app up and running very quickly for a proof of concept / prototype, late on last year, but I'm starting to realise that I really need to understand it a lot better and I can't put it down for two months and expect to be able to just pick it up again... 😞

Markus Åkerlund Larsson11:02:11

@maleghast I don't really know anything about javascript/the DOM, but I put together a survey form system last week, and I just put my data into clojure datastructures using the onchange attribute and then queried that, but there's probably a more direct way of doing it.


on-change is the idiomatic place to do this!


@c09mld - Honestly, based on discussions elsewhere, this does seem to be the "received" way of working with Reagent. I was just hoping that I could avoid "polluting" my app-state with state information about my form, as it feels icky to have display state data in amongst the domain/app data, but I guess that's what I need to do to get the result I want 🙂


A common pattern is to use a local reagent/atom in your form component for state that is truly local to only that component.


Thanks anyway

Matthew Davidson (kingmob)16:02:54

Does anyone have any experience sharing a ratom between Reagent and Om? We have an older codebase using Om, and would like to transition to Reagent while sharing the same source of truth


@kingmob not sure if you can mix then But you can use om-next components in reagent For examploe

(defui Foo
       (let [{:keys [count]} (om/props this)]
         (dom/div nil count)))
(def ui-foo (om/factory Foo))
(def ratom (r/atom {:count 42}))
(defn reagent-stuff
   [ui-foo @ratom]
   [:button {:on-click #(swap! ratom update :count inc)} "+"]])

Matthew Davidson (kingmob)18:02:34

Thanks. Our version is original Om, though.


That odd reify component? I think that defui is just a macro for it.

Matthew Davidson (kingmob)18:02:01

OK, I might try that then. Thx!


Please feedback me 😄 I'm on oposite direction, I'm planning to write om components in my re-frame app and at the end, switch the "state management".

Matthew Davidson (kingmob)14:02:34

Well, based on some sample tests from yesterday, it appears Om can use a ratom ok. Wouldn’t be surprised if there were some weird edge cases, tho