diff --git a/src/OrchardCore.Modules/OrchardCore.Forms/Drivers/FormInputElementPartDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Forms/Drivers/FormInputElementPartDisplayDriver.cs index 34ea04efa2e..53dfd0b9143 100644 --- a/src/OrchardCore.Modules/OrchardCore.Forms/Drivers/FormInputElementPartDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Forms/Drivers/FormInputElementPartDisplayDriver.cs @@ -1,14 +1,24 @@ +using System; using System.Threading.Tasks; +using Microsoft.Extensions.Localization; using OrchardCore.ContentManagement.Display.ContentDisplay; using OrchardCore.DisplayManagement.ModelBinding; using OrchardCore.DisplayManagement.Views; using OrchardCore.Forms.Models; using OrchardCore.Forms.ViewModels; +using OrchardCore.Mvc.ModelBinding; namespace OrchardCore.Forms.Drivers { public class FormInputElementPartDisplayDriver : ContentPartDisplayDriver { + private readonly IStringLocalizer S; + + public FormInputElementPartDisplayDriver(IStringLocalizer stringLocalizer) + { + S = stringLocalizer; + } + public override IDisplayResult Edit(FormInputElementPart part) { return Initialize("FormInputElementPart_Fields_Edit", m => @@ -23,6 +33,11 @@ public async override Task UpdateAsync(FormInputElementPart part if (await updater.TryUpdateModelAsync(viewModel, Prefix)) { + if (String.IsNullOrWhiteSpace(viewModel.Name)) + { + updater.ModelState.AddModelError(Prefix, nameof(viewModel.Name), S["A value is required for Name."]); + } + part.Name = viewModel.Name?.Trim(); part.ContentItem.DisplayText = part.Name; }