Sitecore 9 Forms: Uncaught TypeError: Cannot read property ‘unobtrusive’ of undefined

Are you getting this error on Sitecore 9 Forms Submission? I got it and it took me some time to figure out. It’s all related to Validation. Here are the points to check to narrow down the issue —

  • If you have form fields set it to mandatory, change it to optional and see if that makes the submission successful. If so, one of the field validation is causing trouble.

  • It happens for custom form control quite often, where you need add the validation to razor view file and make sure you have this attribute – GenerateUnobtrusiveValidationAttributes.
<label for="@Html.IdFor(m => Model.Value)" class="@Model.LabelCssClass">@Html.DisplayTextFor(t => Model.Title)</label>
<select data-trigger class="@Model.CssClass @Model.Name" name="@Html.NameFor(m => Model.Value)" id="@Html.IdFor(m => Model.Value)" data-sc-tracking="@Model.IsTrackingEnabled" data-sc-field-name="@Model.Name" @Html.GenerateUnobtrusiveValidationAttributes(m => m.Value)>
</select>
@Html.ValidationMessageFor(m => Model.Value)
  • Compare your custom control razor file to any one of inbuilt form controls ([iis-site-folder]\Views\FormBuilder\FieldTemplates ) like below and if you see any difference on attributes, add it out.
  • Finally a simple check: make sure to publish all the forms and view the landing page in live mode(not in preview mode)

Hope this helps. Happy sitecoring.

2 Responses

  1. Mark Lowe says:

    I had the same issue but it was due to jQuery being in noConflict mode. The data-ajax-success method contains references to $. which is undefined in this case.
    Creating a Forms.RenderForms Pipeline processor that replaces $. with jQuery. solved the problem.

    public override void Process(RenderFormEventArgs args)
    {
    var attributes = args.Attributes[“data-ajax-success”] as string;
    if (string.IsNullOrEmpty(attributes))
    {
    return;
    }

    args.Attributes[“data-ajax-success”] = attributes.Replace(“$.”, “jQuery.”);
    }

Leave a Reply

Your email address will not be published. Required fields are marked *