Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Required valid for form element name #13557

Merged
merged 1 commit into from
Apr 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<FormInputElementPart>
{
private readonly IStringLocalizer S;

public FormInputElementPartDisplayDriver(IStringLocalizer<FormInputElementPartDisplayDriver> stringLocalizer)
{
S = stringLocalizer;
}

public override IDisplayResult Edit(FormInputElementPart part)
{
return Initialize<FormInputElementPartEditViewModel>("FormInputElementPart_Fields_Edit", m =>
Expand All @@ -23,6 +33,11 @@ public async override Task<IDisplayResult> 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."]);
MikeAlhayek marked this conversation as resolved.
Show resolved Hide resolved
}

part.Name = viewModel.Name?.Trim();
part.ContentItem.DisplayText = part.Name;
}
Expand Down