Skip to content

Instantly share code, notes, and snippets.

@giuliohome giuliohome/OpenDetails.fs
Last active Jul 30, 2019

Embed
What would you like to do?
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
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
You can’t perform that action at this time.