Skip to content

Javascript with Stipple doesn't work. #288

Description

@gioneves

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions