dotnet-websharper / ui

A reactive UI library for WebSharper.
https://websharper-samples.github.io/ui/
Apache License 2.0
77 stars 22 forks source link

Handler doesn't bind to action template hole (C#) #191

Open V0d01ey opened 6 years ago

V0d01ey commented 6 years ago

Binding a handler to ws-onclick hole results in exception "Invalid hole, expected quoted event: ".

<button id="sendUT" type="button" ws-onclick="sendUTClick">Add</button>
    public class Server
    {
...
        [Website]
        public static Sitelet<object> Main =>
            new SiteletBuilder()
                .With<Home>((ctx, action) =>
                    Page(ctx, action, "Home",
                        doc(
                            h1("Say Hi to the server!"),
                            div(client(() => Client.Main())), 
                            new Template.Uploaddialogtemplate()
                                .sendUTClick((tev) => Client.SendUTClickHandler(tev))   // <--  assigning method to handler-hole
                                .Elt()
                        )
                    )
                )
                .With<About>((ctx, action) =>
                    Page(ctx, action, "About",
                        doc(
                            h1("About"),
                            p("This is a template WebSharper client-server application.")
                        )
                    )
                )
                .Install();
    }

    [JavaScript]
    public static class Client
    {
...
        static public void SendUTClickHandler(WebSharper.UI.Templating.Runtime.Server.TemplateEvent<Template.Uploaddialogtemplate.Vars, WebSharper.JavaScript.Dom.MouseEvent> tev)
        {            
            JS.Alert("test");
        }
    }

Stack trace of the exception on startup.

[Exception: Invalid hole, expected quoted event: sendUTClick]
   Microsoft.FSharp.Core.PrintFormatToStringThenFail@1379.Invoke(String message) +46
   WebSharper.UI.Templating.Runtime.Server.writeElement@368(FSharpOption`1 name, Boolean keepUnfilled, FSharpOption`1 inlineBaseName, Dictionary`2 requireResources, Boolean plain, FSharpList`1 extraAttrs, RenderContext ctx, Boolean isRoot, Boolean plain@368-1, String tag, Attr[] attrs, FSharpOption`1 wsVar, Node[] children) +224
   WebSharper.UI.Templating.Runtime.writeNode@386-1.Invoke(Node _arg8) +197
   WebSharper.UI.Templating.Runtime.Server.writeElement@368(FSharpOption`1 name, Boolean keepUnfilled, FSharpOption`1 inlineBaseName, Dictionary`2 requireResources, Boolean plain, FSharpList`1 extraAttrs, RenderContext ctx, Boolean isRoot, Boolean plain@368-1, String tag, Attr[] attrs, FSharpOption`1 wsVar, Node[] children) +730
   WebSharper.UI.Templating.Runtime.writeNode@386-1.Invoke(Node _arg8) +197
   WebSharper.UI.Templating.Runtime.Server.writeTemplate@308(FSharpOption`1 name, Boolean keepUnfilled, FSharpOption`1 inlineBaseName, Dictionary`2 requireResources, Template template, Boolean plain, FSharpList`1 extraAttrs, RenderContext ctx) +195
   WebSharper.UI.Templating.Runtime.write@486-1.Invoke(Context ctx, HtmlTextWriter w, Boolean r) +400
   WebSharper.UI.Elt.Write(Context ctx, HtmlTextWriter h, FSharpOption`1 res) +43
   <StartupCode$WebSharper-UI>.Write@87-1.Invoke(Doc d) +32
   Microsoft.FSharp.Primitives.Basics.List.iter(FSharpFunc`2 f, FSharpList`1 x) +38
   WebSharper.UI.Templating.Runtime.writeNode@386-1.Invoke(Node _arg8) +902
   WebSharper.UI.Templating.Runtime.Server.writeElement@368(FSharpOption`1 name, Boolean keepUnfilled, FSharpOption`1 inlineBaseName, Dictionary`2 requireResources, Boolean plain, FSharpList`1 extraAttrs, RenderContext ctx, Boolean isRoot, Boolean plain@368-1, String tag, Attr[] attrs, FSharpOption`1 wsVar, Node[] children) +730
   WebSharper.UI.Templating.Runtime.writeNode@386-1.Invoke(Node _arg8) +197
   WebSharper.UI.Templating.Runtime.Server.writeElement@368(FSharpOption`1 name, Boolean keepUnfilled, FSharpOption`1 inlineBaseName, Dictionary`2 requireResources, Boolean plain, FSharpList`1 extraAttrs, RenderContext ctx, Boolean isRoot, Boolean plain@368-1, String tag, Attr[] attrs, FSharpOption`1 wsVar, Node[] children) +730
   WebSharper.UI.Templating.Runtime.writeNode@386-1.Invoke(Node _arg8) +197
   WebSharper.UI.Templating.Runtime.Server.writeElement@368(FSharpOption`1 name, Boolean keepUnfilled, FSharpOption`1 inlineBaseName, Dictionary`2 requireResources, Boolean plain, FSharpList`1 extraAttrs, RenderContext ctx, Boolean isRoot, Boolean plain@368-1, String tag, Attr[] attrs, FSharpOption`1 wsVar, Node[] children) +730
   WebSharper.UI.Templating.Runtime.writeNode@386-1.Invoke(Node _arg8) +197
   WebSharper.UI.Templating.Runtime.Server.writeTemplate@308(FSharpOption`1 name, Boolean keepUnfilled, FSharpOption`1 inlineBaseName, Dictionary`2 requireResources, Template template, Boolean plain, FSharpList`1 extraAttrs, RenderContext ctx) +195
   WebSharper.UI.Templating.Runtime.write@486-1.Invoke(Context ctx, HtmlTextWriter w, Boolean r) +400
   WebSharper.UI.Elt.Write(Context ctx, HtmlTextWriter h, Boolean res) +83
   WebSharper.Sitelets.renderBody@143.Invoke(HtmlTextWriter tw) +112
   <StartupCode$WebSharper-Sitelets>.get_Default@43.Invoke(FSharpOption`1 doctype, FSharpOption`1 title, FSharpFunc`2 writeHead, FSharpFunc`2 writeBody, HtmlTextWriter writer) +277
   WebSharper.Sitelets.writeBody@136.Invoke(Stream stream) +411
   WebSharper.Sitelets.respond@146.Invoke(Response response) +298
   Microsoft.FSharp.Control.args@823-1.Invoke(a a) +87
   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
   Microsoft.FSharp.Control.AsyncIAsyncResult`1.GetResult() +309
   Microsoft.FSharp.Control.AsBeginEndHelpers.endAction(IAsyncResult iar) +80
   System.Web.CallHandlerExecutionStep.InvokeEndHandler(IAsyncResult ar) +212
   System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +166