Fork me on GitHub
#hoplon
<
2016-08-21
>
jjttjj02:08:36

@alandipert: thanks! My first exposure to it was today and it definitely sidetracked me for a while 🙂

beatngu1322:08:30

I have a select element (as part of a form-group) which I create like this:

(select :class "form-control" :value offer-type-input :change #(reset! offer-type-input @%) :id "inputOfferType"
  (if-tpl (cell= (seq offer-types))
    (map #(option :value (:shortname %) (text (:name %))) @offer-types)))
Somehow :change throws an error: Error: No protocol method IDeref.-deref defined for type object: [object Object]. Shouldn’t the type be fine?

micha22:08:28

@beatngu13 are you sure that offer-type-input is a Cell?

micha22:08:45

you can see by printing it to the js console

micha22:08:05

(prn :offer-type-input offer-type-input)

beatngu1322:08:36

Yes, I defined it like this: (def offer-type-input (cell "thesis“)).

micha23:08:05

did you try printing it though?

micha23:08:15

to make sure

micha23:08:21

like in your :change handler

micha23:08:28

print it before you try to reset! it

micha23:08:44

because it's almost certainly not a cell

micha23:08:52

because cells do implement that protocol

micha23:08:18

something else must be shadowing it

micha23:08:15

prn will print something like :offer-type-input #<Cell ...>

micha23:08:22

if it is in fact a cell

beatngu1323:08:30

The input parameter my handler receives somehow doesn’t match. It’s that #object[Object [object Object]]-thing… though offer-type-input is a cell.

micha23:08:14

you can try (.log js/console offer-type-input)

micha23:08:21

that might print something useful

beatngu1323:08:26

Printing to .log js/console reveals Object { originalEvent=Event change, type="change", target=select#inputOfferType.form-control, more…}.

micha23:08:48

that's what offer-type-input is?

micha23:08:54

that's an event object

micha23:08:15

that's what % should be in your handler

beatngu1323:08:59

But shouldn’t that be the cell? How comes % is the event?

micha23:08:27

event handlers are passed the event object as an argument

micha23:08:30

so they can handle it

micha23:08:55

the code you pasted above isn't trying to call reset! on it though

micha23:08:07

it's calling reset! on offer-type-input

micha23:08:41

and the error is because something called reset! on a js object that doesn't implement the IDeref protocol

micha23:08:17

hah i'm confused

micha23:08:48

it's failing to deref

micha23:08:51

not to reset

micha23:08:20

are you using a different version of jquery?

beatngu1323:08:02

I used the code from the inputs demo (except the formula cell for :selected).

beatngu1323:08:53

And I use jQuery 3.1.0.

micha23:08:06

ah that could be the issue

micha23:08:29

maybe events aren't jQuery.Event objects in that version

beatngu1323:08:06

What version do you recommend?

micha23:08:22

hoplon is tested with [cljsjs/jquery "1.9.1-0"]

micha23:08:26

it's a dependency of hoplon

beatngu1323:08:19

I’ll try that out. Thank you!

micha23:08:45

another solution is just don't use the @ shortcut

micha23:08:24

in jq 1.9 it's the same as (.val (js/jQuery (.-target %)))

micha23:08:59

it's just that you type that a million times so we made a fancy shortcut and coopted that protocol to be able to use the @ reader macro

beatngu1323:08:59

That does the trick!

micha23:08:34

which one?

beatngu1323:08:05

(.val (js/jQuery (.-target %))) instead of using the deref macro.

beatngu1323:08:11

With jQuery 3.1.0.

micha23:08:27

they must have changed the name of the constructor or something

beatngu1323:08:55

Thanks a lot @micha! I was super desperate… 😅

micha23:08:22

you're welcome 🙂

micha23:08:43

you may want to use the 1.9 version of jquery if you run into more issues

beatngu1323:08:45

The version of Bootstrap I use is compatible with jQuery 1.9.1 – 3, so I probably switch to 1.9.1.