I am using WebSharper 4.3.9 and am using WebSharper.UI to try to get two way binding of variables in a web page.
I can get things working when I create the HTML elements in the f# code.
let Main () =
let rvInput = Var.Create ""
let viewInput = View.FromVar rvInput
let submit = Submitter.CreateOption rvInput.View
div [] [
Doc.Input [] rvInput
Doc.Button "Send" [] submit.Trigger
p [] [textView viewInput] // input is mirrored here
...
]
When the user enters text into the rvInput element, it is mirrored to the p[]
But when I have an html template that contains
...
<input ws-var="Email" type="email" placeholder="Your Email" autofocus="">
<button ws-onclick="Login">Login</button>
${ServerResponse}
<div ws-hole="EmailEcho" class="echo-input"></div>
...
and do the following
type LoginTemplate = Template<"Login.html">
let LoginWidget () =
let Email = Var.Create "testing"
let viewInput = View.FromVar Email
let serverResponse = Var.Create ""
LoginTemplate()
.ServerResponse(serverResponse.View)
.EmailEcho(viewInput) // trying to echo what user types on to page
.Login(fun e ->
async {
let! res = Server.LoginClicked e.Vars.Email.Value
serverResponse.Set res // set the server response elem on page !this works
return ()
} |> Async.StartImmediate
)
.Doc()
The ${ServerResponse} element is replaced with the response from the onclick event
But I cannot mirror the text that the user enters into the email field into the emailEcho field.
So I am wondering what I can do to get the users input mirrored into the
<div ws-hole="EmailEcho" class="echo-input"></div>
in the template
Many thanks and very sorry for such a long question Derek