Fix ViewContext.FormContext not being set during BeginUmbracoForm (#13914)

* Fix ViewContext.FormContext not being set during BeginUmbracoForm

Client validation is broken without this if there are multiple forms with the same field names on a page.

* Tweaked comment

(cherry picked from commit 62b49c7ea7)
This commit is contained in:
kiasyn
2023-03-14 02:37:51 +13:00
committed by Sebastiaan Janssen
parent 7c77fd1ca9
commit e9d17d3b9f

View File

@@ -767,6 +767,12 @@ public static class HtmlHelperRenderExtensions
nameof(controllerName));
}
// Create a new form context in order to ensure client validation is set properly when adding multiple forms in a page. More context in PR #13914.
html.ViewContext.FormContext = new FormContext
{
CanRenderAtEndOfForm = true
};
IUmbracoContextAccessor umbracoContextAccessor = GetRequiredService<IUmbracoContextAccessor>(html);
IUmbracoContext umbracoContext = umbracoContextAccessor.GetRequiredUmbracoContext();
var formAction = umbracoContext.OriginalRequestUrl.PathAndQuery;