Sitecore 9.0 Formbuilder error on mandatory fields

I'm getting an unusual error when using the Form builder. This is almost certainly coming from custom code in our application but I am struggling to find where or what kind of code could be breaking this component.

When I save a form through form builder, if any of the fields is set as Mandatory, the form will fail to reload after saving. Saving works as expected for forms with no required fields. After saving, the form builder displays a generic "The form was not loaded due to an error" message. Using the network tab in chrome dev tools, I browse to the service URL that is returning a 500 error: [Site URL]/formbuilder/load?id=[form ID]&sc_formmode=edit&sc_formlang=en&_=1546536213147.

At this URL, I am able to see that the actual error is "Either ErrorMessageString or ErrorMessageResourceName must be set, but not both." stemming from the "@Html.GenerateUnobtrusiveValidationAttributes(m => m.Value)" call in the view for that field, i.e. \Views\FormBuilder\FieldTemplates\Password.cshtml

I have tried restoring to out of the box databases and also removing any custom configs from my local site and neither of those resolve the issue, so it seems that the issue is specific to the code. I'm looking through the solution for any instances where we set those ErrorMessageString or ErrorMessageResourceName properties and not turning anything up. It's also worth mentioning that we have not modified the form builder Views.

Has anyone encountered this issue in the past, or can anyone think of an example of custom code that would break a Sitecore component in this way?

  • I found the source of this issue. We had followed this article to create a Data Annotations Provider that localized our data annotations: www.codeproject.com/.../A-Simple-and-Effective-Way-to-L

    This was incorrectly populating the ErrorMessageString when it was initially null. To resolve this, I added a condition to continue with the for loop if the attribute was a ValidationAttribute but the ErrorMessage was null, rather than supplying a new message.