Fork me on GitHub
#reagent
<
2019-12-02
>
Emmanuel16:12:44

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

p-himik16:12:35

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

rgm19:12:47

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
rgm20:12:44

it is! thank you.

rgm20:12:13

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

rgm20:12:31

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

rgm20:12:01

(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

p-himik17:12:08

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

p-himik17:12:18

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

p-himik17:12:23

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

p-himik17:12:18

It has to be a proper <form> , with a proper <button>that submits the form. More details and examples: https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Form_validation#The_required_attribute

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.

p-himik11:12:23

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.

p-himik11:12:32

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

p-himik11:12:13

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