Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Javascript with Stipple doesn't work. #288

Open
gioneves opened this issue Sep 16, 2024 · 0 comments
Open

Javascript with Stipple doesn't work. #288

gioneves opened this issue Sep 16, 2024 · 0 comments

Comments

@gioneves
Copy link

gioneves commented Sep 16, 2024

I have this code in Stipple:

import Stipple
import StippleUI
import Genie

@Stipple.vars reactives begin
name::String = "World!"
end

Stipple.Layout.add_script("https://cdn.jsdelivr.net/npm/sweetalert2@11")

############ javascript code (PROBLEM) ############
lib_module() = [
  Stipple.script(type ="module", "
    // script code goes here
    document.getElementsByClassName('btn1')[0].addEventListener('click', function() {
      Swal.fire({title: 'Stipple Fire!'})
    })
    ")
]

@Stipple.deps lib_module
############ javascript code (PROBLEM) ############

function ui()

finalMatch = """
<button class="btn1">Click me!</button>
<q-input v-model="name"/>
<p>Typed text: {{ name }}</p>
"""

return finalMatch

end

Stipple.route("/") do
Stipple.page(
  Stipple.init(reactives),
  ui()
) |> Stipple.html
end

Stipple.up()

But Sweet Alert's javascript doesn't work. I don't know what I did wrong, I followed the steps in the documentation, but I don't think I did something right.

I could do it like this, with onclick in the button tag:

<button class="btn1" onclick="Swal.fire({title: 'Stipple Fire!'})">Click me!</button>

But I would like to access the script normally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant