Quantcast
Viewing all articles
Browse latest Browse all 43

Sitecore Web Forms for Marketers Adds jQuery Scripts to Your Pages

Recently I had an issue with a JavaScript in a Sitecore 8.2 update 3 installation that was throwing errors on some pages and not on others. I started comparing the different pages and realized that the error was only happening on pages with WFFM forms so I looked through the markup only to discover that there was a reference to an ancient jQuery v. 1.10.2 at the start of the page.

<script src="/sitecore/shell/Controls/Lib/jQuery/jquery-1.10.2.min.js" type="text/javascript"></script>

The odd thing is that there was another reference to a different jQuery file also added by WFFM right above that pointed to another jQuery v. 1.11.4.

<script src="/sitecore modules/web/web forms for marketers/scripts/jquery.js" type="text/javascript"></script>

Needless to say, having two different versions of jQuery loaded is never a stable situation and to make matters worse we were also loading our own jQuery v. 3.2.1 on top of everything else and as they say, three is a crowd and of course that was the root of the issue.

I still have not really figured out why WFFM would load two different versions of jQuery and even further, why it is using such ancient versions. I did some additional digging and discovered that WFFM was also loading another dynamic script through WebResource.axd right after the jquery-1.10.2.min.js file so I looked at it and it was referencing some data attributes on the form fields. That led me suspect that it had something to do with client side validation as it looked a lot like the data attributes that was added with the unobtrusive form validation that was introduced in asp.net 4.5.

By now I was looking at my options for solving this issue. It looked like I had three different ways to try to solve the issue. My first option was to replace the jquery-1.10.2.min.js file with a blank file and the second option was to replace the contents of the file with either jQuery v. 1.11.4 or 3.2.1 to see if this would make everything work together. However, these options did not really seem safe, as it was just as likely to break something in the WFFM client-side validation. I am guessing that they are including an ancient jQuery version because they need to in order to keep something else from breaking and I was not about to find out what.

So instead, I went with the third option and looked into whether disabling the unobtrusive client-side validation would also stop WFFM from inserting the jQuery script as it looked like it was somehow all linked together. I have actually had my pains with the unobtrusive validation in the past so I pretty much knew that it can be disabled by adding an app setting to the web.config.

<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />

I added the setting and to my amazement, WFFM actually did stop inserting the jQuery reference and instead inserted a script block with the client-side validation directly in the page. Just as normal asp.net would.

Normally by now, I would be thrilled and it did admittedly solve my initial JavaScript conflict. However, I just have to live with the fact that I still have two different versions of jQuery on my pages as WFFM is still loading jQuery v. 1.11.4 and I lost my unobtrusive validation in the process as well.

As a quick side note, this behavior is of course only related to WFFM and not to the unobtrusive form validation in general. ASP.Net is not using jQuery or forcing anyone to insert references to ancient jQuery scripts.


Viewing all articles
Browse latest Browse all 43

Trending Articles