Last active
July 30, 2019 09:50
-
-
Save giuliohome/29f278f24bf752109b8e94682e69e8ea to your computer and use it in GitHub Desktop.
Create a form to post a request with parameter for a new detail tab and render it into html, all typesafe, from f# to javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let (|==>) (param_name, param_id) (safe_url:EndPoint) = | |
let router = Router.Infer() | |
let url = router.Link(safe_url) | |
form [attr.target "_blank"; attr.action url; attr.id ("form" + param_id); attr.method "POST" ] [ | |
a [ on.click (fun el ev -> | |
let frm = JS.Document.GetElementById ("form" + param_id) |> As<HTMLFormElement> | |
frm.Submit() | |
) ] [text param_id] | |
input [attr.``type`` "hidden"; attr.name param_name; attr.value param_id] [] | |
] | |
let ToHtml (doc:Doc) : JQuery = // string = | |
let magic = JS.Document.CreateElement "magic" | |
doc |> Doc.Run magic | |
//magic.InnerHTML // event handlers don't stay when taking the HTML string | |
// Thanks to the guru - Loïc Denuzière - @Tarmil https://gitter.im/intellifactory/websharper?at=5d400b3c7e00fc4ace7568b1 | |
JQuery.Of(magic) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment