Fork me on GitHub

is there a good explanation for why the notation for accessing properties of the react event object is .-<property> ?


That's just JS interop of CLJS. Has nothing to do with React/Reagent.


potential gotcha I've learned / cargo-culted ... using (.-a-property foo) tends to be a source of a lot of my advanced compilation issues because the closure compiler may or may not have enough visibility. Since I don't quite understand when that is, I've started to use (goog.object/getValueByKeys foo "a-property") in general when accessing objects that aren't mine, since (as I understand it) GCC won't rename strings and this effectively it tells it to back off from aggressively renaming it.

👍 8

it is! thank you.


I think I read it when Thomas wrote it, but the full implications have been a while sinking in.


(as, I've found, with most Clojure explanatory material ... it rewards annual re-reads).


(once again realizing @U05224H0W is a treasure and we are lucky to have him).

❤️ 4
👍 4
Ramon Rios17:12:45

Hello. i have a html input field and would like to put a required tag on it. I would like to know if it's possible.

Ramon Rios17:12:30

{:value (get-in @current [:addresses address-type id]) :type type :on-change on-change-action :disabled disabled? :required}
This is my current try


I mentioned {:required true} in the other channel. Did it not work?


By "no" you mean it was not added to the list of the <input> attributes at all? Or that it did not show any pop-up when you didn't enter anything and tried to submit the form?

Ramon Rios17:12:40

Second sentence

Ramon Rios17:12:44

In html, it appears the required tag


OK. Did you actually build a proper <form> ? Can you show the code that renders the form and includes anything that's relevant?

Ramon Rios17:12:22

Maybe the thing was this form, probably it's not well formed


It has to be a proper <form> , with a proper <button>that submits the form. More details and examples:

Ramon Rios11:12:06

I found out what was going on.

Ramon Rios11:12:09

The submit button was executing the :on-click in the same time that the field was validated.

Ramon Rios11:12:35

I looking foward on how to execute the validation before execute the save function.


The intended way to use HTML's form validation is not to bypass form's submission but to use it. I would move the button's :on-click handler to the form's :on-submit handler. Since you're probably writing an SPA application, you'll need to call preventDefault on the event passed in that handler.


How I've done it in a login form once:

[:form {:on-submit (fn [e]
                     (.preventDefault e)
                     (dispatch [::mae/login @login @password]))}

Ramon Rios11:12:16

And it will only dispatch when all required fields are fullfiled


I think so, yes. :on-submit should be called only if all fields are valid. You can easily check it.

Ramon Rios13:12:49

Worked. Thanks