Fork me on GitHub
#reagent
<
2018-02-19
>
maleghast10:02:04

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

maleghast10:02:38

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

maleghast10:02:23

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

maleghast11:02:22

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

maleghast11:02:05

@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...

maleghast11:02:19

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

maleghast11:02:17

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.

curlyfry07:02:37

on-change is the idiomatic place to do this!

maleghast12:02:03

@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 🙂

curlyfry07:02:12

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

maleghast12:02:05

Thanks anyway

kingmob16: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

souenzzo18:02:59

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

(defui Foo
       [this]
       (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
  []
  [:div 
   [ui-foo @ratom]
   [:button {:on-click #(swap! ratom update :count inc)} "+"]])

kingmob18:02:34

Thanks. Our version is original Om, though.

souenzzo18:02:20

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

kingmob18:02:01

OK, I might try that then. Thx!

souenzzo18:02:53

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".

kingmob14: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