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
This commit is contained in:
kiasyn
2023-03-14 02:37:51 +13:00
committed by GitHub
parent 7c30da9fbf
commit 62b49c7ea7

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;