Cannot add MVC form in the Experience Editor

  • Adding an MVC form to a page in the Experience Editor might fail with the following error in browser's console:

    Uncaught TypeError: $ is not a function
        at eval (eval at <anonymous> (16326293963705728857.JS:23), <anonymous>:3:31)
        at eval (eval at <anonymous> (16326293963705728857.JS:23), <anonymous>:8:15)
        at eval (<anonymous>)
        at 16326293963705728857.JS:23
        at Function.globalEval (16326293963705728857.JS:23)
        at HTMLScriptElement.bl (16326293963705728857.JS:23)
        at Function.each (16326293963705728857.JS:23)
        at init.domManip (16326293963705728857.JS:24)
        at init.domManip (16326293963705728857.JS:40)
        at init.append (16326293963705728857.JS:24)

    The issue occurs due to missing scripts that are required to be loaded before a form is rendered. They are added by the @Html.RenderFormScripts() helper in case when the MvcOuterLayout.cshtml layout is applied as described in the official Sitecore documentation.

  • To resolve the issue, add the following scripts manually to the <head> section of your layout (.cshtml file):

    • For Sitecore XP 9.0 Initial Release — 9.0 Update-2, add the following scripts to the <head> section of your layout:
      <script src="/sitecore%20modules/Web/ExperienceForms/scripts/jquery-2.1.3.min.js"></script>
      <script src="/sitecore%20modules/Web/ExperienceForms/scripts/jquery.validate.min.js"></script
      <script src="/sitecore%20modules/Web/ExperienceForms/scripts/jquery.validate.unobtrusive.min.js"></script>
      <script src="/sitecore%20modules/Web/ExperienceForms/scripts/jquery.unobtrusive-ajax.min.js"></script>
      <script src="/sitecore%20modules/Web/ExperienceForms/scripts/form.validate.js"></script>
      <script src="/sitecore%20modules/Web/ExperienceForms/scripts/form.tracking.js"></script>
    • For Sitecore XP 9.1 Initial Release and higher, add the following scripts to the <head> section of your layout:
      <script src="/sitecore%20modules/Web/ExperienceForms/scripts/jquery-2.1.3.min.js"></script>
      <script src="/sitecore%20modules/Web/ExperienceForms/scripts/jquery.validate.min.js"></script>
      <script src="/sitecore%20modules/Web/ExperienceForms/scripts/jquery.validate.unobtrusive.min.js"></script>
      <script src="/sitecore%20modules/Web/ExperienceForms/scripts/jquery.unobtrusive-ajax.min.js"></script>
      <script src="/sitecore%20modules/Web/ExperienceForms/scripts/form.validate.js"></script>
      <script src="/sitecore%20modules/Web/ExperienceForms/scripts/form.tracking.js"></script>
      <script src="/sitecore%20modules/Web/ExperienceForms/scripts/form.conditions.js"></script>

Applies to:

CMS 9.0 - 9.2

April 14, 2020
April 14, 2020

Reference number:

343493

Keywords: 

  • Sitecore Forms