Cannot add MVC form in the Experience Editor


Description

Adding an MVC form to a page in the Experience Editor might fail with the following error in the 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 when the MvcOuterLayout.cshtml layout is applied as described in the official Sitecore documentation. This applies to Sitecore Forms 9.0.0 - 9.2.0.

Solution

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