We have moved to GitHub Issues
You are viewing the read-only archive of Umbraco's issue tracker. To create new issues, please head over to GitHub Issues.
Make sure to read the blog posts announcing the move for more information.
Created by Jeffrey Schoemaker 27 Oct 2016, 13:51:27 Updated by Mads Krohn 23 Aug 2018, 08:46:00
Tags: Unscheduled Gold partnerDuplicates: U4-10685
Relates to: CON-917
Hi,
I have the same problem as stated in this our-post (https://our.umbraco.org/forum/umbraco-forms/78683-umbraco-adds-scripts-and-css-even-if-no-form-is-inserted).
I have this code on my page followed the guide on our (https://our.umbraco.org/documentation/products/umbracoforms/developer/Rendering-Scripts/):
TempData["UmbracoForms"] is null until I reach a page with a Umbraco Form in a RTE. At that moment TempData["UmbracoForms"] is filled correctly with the GUID. If I then go to another page without a Umbraco Form on it. The TempData["UmbracoForms"] is still filled with the GUID and thus renders javascripts and css for Forms.
It looks like TempData["UmbracoForms"] is more sticky than supposed too.
Regards,
Jeffrey
Could it be that you render the TempData on a page that doesn't return a 200 OK
?
From https://stackoverflow.com/questions/7630678/tempdata-not-being-cleared :
Below are some of the key points to note when using Temp data.
A read access to temp data doesn't remove items from the dictionary immediately, but only marks for deletion.
Temp data will not always remove the item that has been accessed. It only removes the item when an action results in an Http 200 status code (ViewResult/JsonResult/ContentResult etc).
In case of actions that result in an Http 302 (such as any redirect actions), the data is retained in storage even when it is accessed.
This could possibly fix it, adding to the FormsRenderScripts
macro
if(TempData["UmbracoForms"]) != null TempData["UmbracoForms"] = null;
So currently the RenderUmbracoFormScripts.cshtml
looks like this:
@inherits Umbraco.Web.Macros.PartialViewMacroPage @using Umbraco.Forms.Web.Controllers
@if (TempData["UmbracoForms"] != null)
{
foreach (var form in (List
Update could be:
@inherits Umbraco.Web.Macros.PartialViewMacroPage @using Umbraco.Forms.Web.Controllers
@if (TempData["UmbracoForms"] != null) { // Reading TempData["UmbracoForms"] should have set it to null but this doesn't happen if this request didn't return a 200 OK status, explictly clear it so that on the next request the scripts don't get rendered if(TempData["UmbracoForms"]) != null { TempData["UmbracoForms"] = null; }
foreach (var form in (List<Guid>)TempData["UmbracoForms"])
{
Html.RenderAction("Render", "UmbracoForms", new { formId = form, mode = "script"});
}
}
Would you have a chance to test this on an affected site @jeffrey.schoemaker@perplex.nl ?
@sebastiaan Your Solutions helps with the issue http://issues.umbraco.org/issue/CON-1481 DatePicker scripts appearing in source twice.
@sebastiaan I was having the same issue so implemented your solution. It does seem to fix the issue although I did have to move the code setting TempData to null to below the for loop where it was accessed.
@suzyb What for loop are we talking about?
Oh haha never mind, I see it now :)
Ended up with the following:
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@using Umbraco.Forms.Web.Controllers
@{
var formsToRender = new List
// Reading TempData["UmbracoForms"] should have set it to null but this doesn't
// happen if this request didn't return a 200 OK status. https://stackoverflow.com/a/7630709/5018
// Explictly clear it so that on the next request the scripts don't get rendered.
TempData.Remove("UmbracoForms");
}
@foreach (Guid form in formsToRender) { Html.RenderAction("Render", "UmbracoForms", new ); }
Just upgraded to Forms 7.0.3, and this issue is still present. Very easy to see if you have two browser tabs with the same site, and a form rendered in each tab. object forms = TempData["UmbracoForms"]; already contains 2 guids at that point, so forcefully removing the temp data does nothing. Umbraco version is 7.10.4.
Besides, looping the script rendering is a really bad idea, as it loads umbracoforms.js etc twice. In there is an ancient $('.contour input[type=submit]').not('.cancel').click() method that will gladly register twice, so you end up with a double submission if you ever loaded two forms on the same page anyways.
Seeing this on Umbraco 7.11.1, Forms 7.03 on cloud and localhost, view two different (GUID) forms in a row and formsToRender
contains two values. First value is for previous form visited, second appears to be the current form, when both or wrong script is included the client has script issues with conditions and validations or worse (duplicate pikaday
instances cause stack overflow and tab crashes).
If it makes any difference these forms sit behind default Membership provider; have not tested other scenarios.
Workaround for now:
`` @if (formsToRender.Any()) { Html.RenderAction("RenderFormScripts", "UmbracoForms", new );
if (formsToRender.Count > 1)
{
LogHelper.Warn<PartialViewMacroPage>(string.Format("{0} form guids found to render scripts, only rendering last script. Guids are: {1}", formsToRender.Count, string.Join(";", formsToRender.Select(guid => guid.ToString()))));
}
} ``
@sebastiaan this is still an issue, could you open the ticket again? Also, Forms v. 7.0.3 isn't on the list of affected versions :)
Priority: Normal
Type: Bug
State: Fixed
Assignee: Sebastiaan Janssen
Difficulty:
Category:
Backwards Compatible: True
Fix Submitted:
Affected versions: 4.4.2, 7.0.2
Due in version: 6.0.7
Sprint:
Story Points:
Cycle: