aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

passing arguments to onclick in svg

Open furoraest opened this issue 8 years ago • 2 comments

when doing: button onclick=@(() => MyFunction(my.Variable)) it works as expected when binding svg onclick without arguments, eg: onclick=@TestFunction, also works as expected when trying to bind onclick with variables within svg, errors begin:

Uncaught Error: Microsoft.AspNetCore.Blazor.Browser.Interop.JavaScriptException: Cannot set attribute on non-element child Error: Cannot set attribute on non-element child at BrowserRenderer.applyEdits (BrowserRenderer.ts:76) at BrowserRenderer.updateComponent (BrowserRenderer.ts:33) at renderBatch (Renderer.ts:45) at Array. (mono.js:1) at _emscripten_asm_const_iiiiii (mono.js:1) at wasm-function[2679]:25 at wasm-function[3541]:44 at wasm-function[3548]:408 at wasm-function[3550]:224 at wasm-function[3766]:189 at Microsoft.AspNetCore.Blazor.Browser.Interop.RegisteredFunction.InvokeUnmarshalled[T0,T1,T2,TRes] (System.String identifier, T0 arg0, T1 arg1, T2 arg2) <0x1c21a40 + 0x00054> in <92ed9c6772a34798bccecc99cc26cbcd>:0 at Microsoft.AspNetCore.Blazor.Browser.Interop.RegisteredFunction.InvokeUnmarshalled[T0,T1,TRes] (System.String identifier, T0 arg0, T1 arg1) <0x1c21958 + 0x00022> in <92ed9c6772a34798bccecc99cc26cbcd>:0 at Microsoft.AspNetCore.Blazor.Browser.Rendering.BrowserRenderer.UpdateDisplay (Microsoft.AspNetCore.Blazor.Rendering.RenderBatch batch) <0x1c21870 + 0x00020> in <92ed9c6772a34798bccecc99cc26cbcd>:0 at Microsoft.AspNetCore.Blazor.Rendering.Renderer.ProcessRenderQueue () <0x1a497b0 + 0x000a4> in <0d9c96ffc9704aa9b088cbbe138126c6>:0 at Microsoft.AspNetCore.Blazor.Rendering.Renderer.DispatchEvent (System.Int32 componentId, System.Int32 eventHandlerId, Microsoft.AspNetCore.Blazor.UIEventArgs eventArgs) <0x1f67f70 + 0x00074> in <0d9c96ffc9704aa9b088cbbe138126c6>:0 at Microsoft.AspNetCore.Blazor.Browser.Rendering.BrowserRenderer.DispatchBrowserEvent (System.Int32 componentId, System.Int32 eventHandlerId, Microsoft.AspNetCore.Blazor.UIEventArgs eventArgs) <0x1f67e08 + 0x00020> in <92ed9c6772a34798bccecc99cc26cbcd>:0 at Microsoft.AspNetCore.Blazor.Browser.Rendering.BrowserRendererEventDispatcher.DispatchEvent (System.String eventDescriptorJson, System.String eventArgsJson) <0x1f5f478 + 0x0005a> in <92ed9c6772a34798bccecc99cc26cbcd>:0 at BrowserRenderer.applyEdits (BrowserRenderer.ts:76) at BrowserRenderer.updateComponent (BrowserRenderer.ts:33) at renderBatch (Renderer.ts:45) at Array. (mono.js:1) at _emscripten_asm_const_iiiiii (mono.js:1) at wasm-function[2679]:25 at wasm-function[3541]:44 at wasm-function[3548]:408 at wasm-function[3550]:224 at wasm-function[3766]:189 at Microsoft.AspNetCore.Blazor.Browser.Interop.RegisteredFunction.InvokeUnmarshalled[T0,T1,T2,TRes] (System.String identifier, T0 arg0, T1 arg1, T2 arg2) <0x1c21a40 + 0x00054> in <92ed9c6772a34798bccecc99cc26cbcd>:0 at Microsoft.AspNetCore.Blazor.Browser.Interop.RegisteredFunction.InvokeUnmarshalled[T0,T1,TRes] (System.String identifier, T0 arg0, T1 arg1) <0x1c21958 + 0x00022> in <92ed9c6772a34798bccecc99cc26cbcd>:0 at Microsoft.AspNetCore.Blazor.Browser.Rendering.BrowserRenderer.UpdateDisplay (Microsoft.AspNetCore.Blazor.Rendering.RenderBatch batch) <0x1c21870 + 0x00020> in <92ed9c6772a34798bccecc99cc26cbcd>:0 at Microsoft.AspNetCore.Blazor.Rendering.Renderer.ProcessRenderQueue () <0x1a497b0 + 0x000a4> in <0d9c96ffc9704aa9b088cbbe138126c6>:0 at Microsoft.AspNetCore.Blazor.Rendering.Renderer.DispatchEvent (System.Int32 componentId, System.Int32 eventHandlerId, Microsoft.AspNetCore.Blazor.UIEventArgs eventArgs) <0x1f67f70 + 0x00074> in <0d9c96ffc9704aa9b088cbbe138126c6>:0 at Microsoft.AspNetCore.Blazor.Browser.Rendering.BrowserRenderer.DispatchBrowserEvent (System.Int32 componentId, System.Int32 eventHandlerId, Microsoft.AspNetCore.Blazor.UIEventArgs eventArgs) <0x1f67e08 + 0x00020> in <92ed9c6772a34798bccecc99cc26cbcd>:0 at Microsoft.AspNetCore.Blazor.Browser.Rendering.BrowserRendererEventDispatcher.DispatchEvent (System.String eventDescriptorJson, System.String eventArgsJson) <0x1f5f478 + 0x0005a> in <92ed9c6772a34798bccecc99cc26cbcd>:0 at Object.callMethod (MonoPlatform.ts:70) at raiseEvent (BrowserRenderer.ts:327) at EventDelegator.onEvent (BrowserRenderer.ts:19) at EventDelegator.onGlobalEvent (EventDelegator.ts:83)

furoraest avatar Jun 06 '18 07:06 furoraest

I ran into this error when trying to change a value that is bound to an SVG element attribute.

Blazor Version: 0.4.0 Browser: Chrome

Index.cshtml:

<svg width="300" height="300">
    <Box></Box>
</svg>

Box.cshtml:

<rect style="fill:rgb(0,0,0);"
      x="@x"
      y="@y"
      width="100"
      height="100"
      onclick=@(() => x += 10)
      />

@functions{
    [Parameter] int x { get; set; }
    [Parameter] int y { get; set; }
}

When you click on the displayed rect in the browser the "Cannot set attribute on non-element child" error is observed.

natewallace avatar Jun 28 '18 14:06 natewallace

Will be fixed in aspnet/Blazor#1175

SteveSandersonMS avatar Jul 23 '18 21:07 SteveSandersonMS