Giter Site home page Giter Site logo

Comments (3)

JanBizub avatar JanBizub commented on May 22, 2024 3

Hello Pim, thank you for reply. I was aware that lambda wont work it was just for illustration. It is reasonable. If I wanted javascript onClick then I add an id to the element using Attr.id reference .js file and assign onClick event there. What I was originally after was a button that redirects user, but I used Elem.a masked by bootstrap as button with href. I like Falco very much so far thank you for creating it. :)

from falco.

pimbrouwers avatar pimbrouwers commented on May 22, 2024

Hi Jan,

Thanks for reaching out.

As you have discovered, the "onClick" attribute doesn't exist in the Attr module. I omitted the JavaScript attributes because the module is easily extended on a per-project basis, and because it is generally considered a poor security practice to allow for the execution of inline JavaScript with your CSP.

Before I leave some example code, I just want to point out that the F# lamba as you have it will not work. The Markup module produces literal HTML, thus the XmlAttribute type expects a string for both the name and value of the attribute. In the case of onclick, the expecation for the value is a string literal that contains executable JavaScript.

module Attr = 
    let onclick v = Attr.create "onclick" v

Elem.button [ Attr.onclick "(function() { console.log('here') })()" ] [ Text.raw "Click" ]
// Equivalent to: <button onclick="(function() { console.log('here') })()">Click</button>

Let me know if that makes sense, or if you have any other questions.

Cheers

from falco.

pimbrouwers avatar pimbrouwers commented on May 22, 2024

Appreciate that! Glad you enjoy it! Tell your friends!

from falco.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.