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

Add Validation type for Validation Summary Part #13560

Merged
merged 1 commit into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
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,6 +1,10 @@
using System.Threading.Tasks;
using OrchardCore.ContentManagement.Display.ContentDisplay;
using OrchardCore.ContentManagement.Display.Models;
using OrchardCore.DisplayManagement.ModelBinding;
using OrchardCore.DisplayManagement.Views;
using OrchardCore.Forms.Models;
using OrchardCore.Forms.ViewModels;

namespace OrchardCore.Forms.Drivers
{
Expand All @@ -13,7 +17,22 @@ public override IDisplayResult Display(ValidationSummaryPart part)

public override IDisplayResult Edit(ValidationSummaryPart part)
{
return View("ValidationSummaryPart_Fields_Edit", part);
return Initialize<ValidationSummaryViewModel>("ValidationSummaryPart_Fields_Edit", model =>
{
model.ModelOnly = part.ModelOnly;
});
}

public override async Task<IDisplayResult> UpdateAsync(ValidationSummaryPart part, IUpdateModel updater, UpdatePartEditorContext context)
{
var model = new ValidationSummaryViewModel();

if (await updater.TryUpdateModelAsync(model, Prefix))
{
part.ModelOnly = model.ModelOnly;
}

return Edit(part);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ namespace OrchardCore.Forms.Models
{
public class ValidationSummaryPart : ContentPart
{
public bool ModelOnly { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace OrchardCore.Forms.ViewModels;

public class ValidationSummaryViewModel
{
public bool ModelOnly { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@{
// HtmlFieldPrefix is the PartName i.e. ValidationPart, which is not needed in Display.
var htmlFieldPrefix = ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix;
ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = "";
ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = String.Empty;

@Html.ValidationMessage(Model.Value.For)

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
<div class="hint">@T["Displays a list of validation errors."]</div>
@using OrchardCore
@using OrchardCore.Forms.ViewModels

@model ValidationSummaryViewModel

<div class="@Orchard.GetWrapperCssClasses()">
<div class="@Orchard.GetEndCssClasses(true)">
<div class="form-check">
<input class="form-check-input" asp-for="ModelOnly">
<label class="form-check-label" asp-for="ModelOnly">
@T["Show Model Only Error"]
</label>
</div>
<div class="hint">@T["When checked, model level errors will be visible otherwise all errors will be visible."]</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@using OrchardCore.Forms.Models
@model ShapeViewModel<ValidationSummaryPart>

<div asp-validation-summary="All"></div>
<div asp-validation-summary="@Model.Value.ModelOnly ? ValidationSummary.ModelOnly : ValidationSummary.All"></div>