Fork me on GitHub
Travis Smith21:03:24

I'm finding that implementing a drop down menu in re-frame is less intuitive than I'd hoped. There's a submit button almost by definition. How would I route a dropdown selection back to my app-db? Should I be using a framework for components like this? As you might imagine, I'm new to front end development, so sorry if this sounds strange.


First, think about this: how would you do it with any other framework, or library, or even vanilla JS?

Travis Smith22:03:59

Yeah, I'm super new at this. I've looked at plain HTML, and I've looked at a ReactJS component tutorial. The part that is tripping me up is that I understand how to implement options, but I don't see conceptually how choosing an option is captured into an action. With a button, you have the :on-click #(dispatch something) pattern, but I don't see any examples of this in a dropdown.


Can you add :on-click handlers to your drop down items?

Travis Smith22:03:37

Here's where I'm at: (defn template-listing-dropdown [] [:div#template-listing-dropdown [:form [:fieldset [:legend "Templates"] [:p [:label "Select list"] [:select#myList {:on-change #(dispatch [:add-template-items test-director])} ;; need to find how to access the :option :value [:option {:value "nothing"} ""] [:option {:value test-director} "Test Director"] [:option {:value "nonced"} "Nonced!"] ]]] ] ])

Travis Smith22:03:24

my :on-change works to trigger a dispatch, but I don't know how to access the values in :option :value to go into that dispatch and customize the response.

Travis Smith22:03:07

I feel like there should be a reference somewhere that I'm missing...looking at React tutorials and it makes sense over there, but re-frame handles state differently.


:on-change function probably accepts some argument (event most likely)


:on-change (fn [event] (-> event .-target .-value))

knubie22:03:36 should give you the value of the selected option


from there you can pass that to your re-frame event


#(dispatch […]) is syntactic sugar for (fn [& args] (dispatch […])) and you can access the first argument in #(dispatch …) with %. So % is the event object

Travis Smith23:03:11

hmm. Thank you. I'll work on this.

👍 4

@UP5089ML1 You may be interested to look at re-com for ideas and further explanation


Either that or the TodoMVC example in the re-frame repository under /examples


If you are dealing with a lot of forms, you might want to look into

👍 4