Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • _R 13 posts 143 karma points
    Jun 16, 2023 @ 15:01
    _R
    0

    Problems while rendering asynchronous form as plugin

    As a developer I was updating an old Umbraco project to Umbraco 10. Since we are using USkinned block components for our new custom editors, I am building some components as App-Plugin, to keep supporting the older grit editors.

    Currently I am stuck at rendering a Form in my editor.cshtml. Note that this is a plugin which does not access @Umbraco.

    I tried several option and for now this one looks like the most obvious solution:

    @await Component.InvokeAsync("RenderFormScripts", new { FormGuid = formGuid, FormTheme = string.Empty});
    

    However, when awaiting this Invocation, I get an error message from the UDI parser: System.FormatException: String "17428" is not a valid udi.

    I must asynchronically call the invocation, otherwise it shows the Task signature.

    For now it looks like it tries to parse an nodeid which has nothing to do with the Form. The Form itself really exists with the proper GUID.

    Does anybody know, where this id came from and how I can accomplish my goal?

  • Simon Napper 84 posts 254 karma points
    Jun 20, 2023 @ 20:11
    Simon Napper
    0

    So just to eliminate options, you're calling the RenderFormScripts component with the parameter FormGuid, is that parameter a GUID/Udi?

    If so, what is the value of formGuid? Guessing it's 17428?

  • _R 13 posts 143 karma points
    Jun 21, 2023 @ 07:26
    _R
    0

    Thanks for the reply! Indeed I was calling the RenderFormScript component with a valid FormGuid which is a valid GUID and not the nodeId. Thats the weird thing. I also tried it with the existing component: RenderFormScript

    @await Component.InvokeAsync("RenderFormScripts", new { FormGuid = formGuid, FormTheme = string.Empty});               
    

    Also with a valid GUID which is available in the database. The result of the code above is that is always results in an error: System.InvalidOperationException: Cannot find form with Id 00000000-0000-0000-0000-000000000000

    When debugging the code the GUID is in proper format and a valid form: {179f1720-c378-46bb-823d-51fbd6a138f0}

    I have no clue how this can't work and why it results in an empty GUID.

  • Simon Napper 84 posts 254 karma points
    Jun 21, 2023 @ 10:30
    Simon Napper
    0

    I'm wondering if it's the naming of the parameters that's causing the issue. Just had a look at

    https://docs.umbraco.com/umbraco-forms/developer/rendering-scripts (granted it's the v11 docs)

    and the RenderFormScripts component is called using the following

     @await Component.InvokeAsync("RenderFormScripts", new { formId, theme = "default" })
    

    rather than

    @await Component.InvokeAsync("RenderFormScripts", new { FormGuid = formGuid, FormTheme = string.Empty}); 
    

    So if you're setting your formGuid to the component parameter name FormGuid rather than not specifying the parameter name or setting it to formId, then it won't be setting your form guid to a parameter which exists in the component, which is probably why it's saying it's empty (00000000-0000-0000-0000-000000000000). Same with the FormTheme parameter as I think this might just be theme.

    Wonder if that might do the trick?

  • _R 13 posts 143 karma points
    Jun 30, 2023 @ 12:53
    _R
    100

    Thank for this replay. This solution gives me the exact same problems. However, I tried to debug a bit more and found out that I could use the UmbracoHelper and use a Marco by refering to it's alias. Next I got the problem that my helper was not instantiated with published content. Therefor I had to set AssignedContentItem with my current page publishedContent. Soo... for an app_plugin cshtml editor this is my current solution which works, also asynchronically:

    UmbracoHelper.AssignedContentItem = ContentProvider.GetCurrentPage();
    await UmbracoHelper.RenderMacroAsync("renderUmbracoForm", new { FormGuid = formGuid, FormTheme = "", ExcludeScripts = "0" });
    
Please Sign in or register to post replies

Write your reply to:

Draft