Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial View scripts only rendering for first form when using multiple forms #670

Closed
benjiew opened this issue Nov 12, 2021 · 4 comments
Closed

Comments

@benjiew
Copy link

benjiew commented Nov 12, 2021

I think this may a bit of an edge case but I noticed that if you render multiple forms on a page, if a form has a field type which requires a partial view that adds script dependencies (like DatePicker.cshtml), only the script references for the first form are added to the page.

There is a workaround of moving the script references into the field type partial view (e.g. FieldType.DatePicker.cshtml) but the fact the DatePicker partial contains these, suggests it should work out of the box.

Specifics

Umbraco Forms 9.0.1 (issue also found in Forms 8.9.0).

Steps to reproduce

Create two forms, one with a datepicker field and one without.
Render the two forms on the same page ensuring the datepicker form is last.
Attempt to click on the datepicker field.
Ensure you render scripts at the bottom of the page.

*As a side note, I have the following code snippet as TempData was not being cleared when I visited a different page (maybe a different bug?)

@if (TempData["UmbracoForms"] != null)
    {
        foreach (var form in TempData.Get<List<Guid>>("UmbracoForms"))
        {          
            @await Component.InvokeAsync("RenderFormScripts", new { formId = form, theme = "bootstrap5" })
        }

        // need to clear TempData otherwise other previously loaded forms persist
        TempData.Remove("UmbracoForms");
    }

Expected result

Datepicker calendar to show.

Actual result

Calendar not showing.

@AndyButland
Copy link

I'm not able to replicate this I'm afraid. Maybe you can see if I'm doing anything different to you?

I've tried with two copies of the same form on a page, or two different forms - in both cases with each form having a single date field.

I find I can use the date picker as expected on both forms.

    @await Umbraco.RenderMacroAsync("renderUmbracoForm", new { FormGuid = Model.ContactForm.ToString(), ExcludeScripts = "1" })
    @await Umbraco.RenderMacroAsync("renderUmbracoForm", new { FormGuid = Model.ContactForm2.ToString(), ExcludeScripts = "1" })
	
	...
	
    @Html.RenderUmbracoFormDependencies()

    @if (TempData["UmbracoForms"] != null)
    {
        foreach (var form in TempData.Get<List<Guid>>("UmbracoForms"))
        {
            @await Component.InvokeAsync("RenderFormScripts", new { formId = form, theme = "bootstrap3-horizontal" })
        }
    }

Have also tried with and without the extra link you've added to clear the TempData.

@benjiew
Copy link
Author

benjiew commented Nov 15, 2021

The first form rendered on the page needs to be without a date field.

@AndyButland
Copy link

I see... and yes, I can replicate that. On V8 too so seems to be an existing bug. Looks like we need to be more precise in the checks to prevent rendering the same scripts and CSS files twice - currently it's doing so only for the first form, but it needs to be doing so for every form, de-duplicating any scripts or stylesheets already rendered from the forms before.

@AndyButland
Copy link

This behaviour has been amended now such that the de-duplication applies at the level of the file rather than the form, which should resolve this issue. Due in 8.10.0 and 9.2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants