Fork me on GitHub
#clojurescript
<
2022-11-04
>
kokonut10:11:47

I am trying to implement this to be able to copy text to a clipboard on the browser. Can someone let me know how I can write this line in cljs? navigator.clipboard.writeText(copyText.value) https://www.w3schools.com/howto/howto_js_copy_clipboard.asp

p-himik10:11:28

It's just plain JS interop: (.. js/navigator -clipboard (writeText (.-value copyText))). Alternatively, if you prefer ->: (-> js/navigator .-clipboard (.writeText (.-value copyText))). Yet another alternative that should work just fine (because, IIRC, navigator is in the js/ namespace): (js/navigator.clipboard.writeText (.-value copyText)).

💯 1
kokonut10:11:59

Thanks a lot!

👍 1
Ted Ciafardini16:11:28

Perhaps more of a javascript question but:

(let [form-data (doto (js/FormData.)
                        (.append "file" file (.-name file)))]      
                  (.append form-data "myarray[]" "adding into array is possible")
                  (.append form-data "myarray[]" "Another one")
                  (.append form-data "myarray[]" "LOL")
                  form-data)
This code adds each item to the array myarray[] which is definitely useful, but not what I expected. https://developer.mozilla.org/en-US/docs/Web/API/FormData/append - here in the docs I don’t see anything about this (using .append with an array) Is this expected and if so why?

Ted Ciafardini16:11:09

When logging Array.from(form-data) I see each added individually as a tuple - not as an additional value in the array

Ted Ciafardini16:11:12

When this FormData is received as a request, it looks more like this: {:myarray [12, 13, 14]}

skylize16:11:11

No. There is no array there. Your code is appending multiple fields to your FormData object, with all of those fields having the same name, and that name being the string "myarray[]".

Ted Ciafardini16:11:00

That’s what I thought too. Something in the codebase is building vectors when the keyword is repeated

Ted Ciafardini16:11:26

by keyword, I mean idx0 of each array

skylize16:11:38

What vector? It is a FormData containing fields. append will add a feild to that FormData, or set would override a field of the same name. When you call Array.from, those fields are iterated as pairs of [name, value] into an Array, where each entry is indexed by a number key.

Ted Ciafardini16:11:27

When the request is received from this form-data in the app, it looks like this: {:myarray [12, 13, 14]} With a vector attached to the repeated string name "myarray[]" I’m thinking it’s happening somewhere in middleware maybe if this isn’t normal javascript behavior

skylize16:11:48

Yeah, that sounds like something in your stack being smart for you; finding a sane way to represent all the values which share a name.

Ted Ciafardini16:11:42

Thanks for taking the time to respond gratitude

☺️ 1
xretaxeous16:11:31

I am trying to create a website that can be crawled properly, should I bet on starting with https://github.com/thheller/next-cljs or https://github.com/thheller/gatsby-cljs?

Annaia Danvers16:11:46

I'm personally still bitter about Gatsby's version handling and history of breaking things, so I vote for the other one by default.

Lone Ranger00:11:38

I don’t have anything against gatsby, but I support bitterness. I too vote for the other one! :star-struck:

Annaia Danvers16:11:31

When Gatsby released v2 they made a bunch of breaking changes, immediately dropped all support for v1, and deleted all the docs for it ... and I was maintaining a v1 site.