Fix model validation error display

This commit is contained in:
2020-01-16 11:09:00 -05:00
parent f0cb5f45c1
commit 15e1c1d59a
4 changed files with 12 additions and 12 deletions
+3 -2
View File
@@ -34,9 +34,10 @@ namespace LeafWeb.WebCms.Controllers
if (!files.Any()) if (!files.Any())
ModelState.AddModelError("Files", "Must select at least one file"); ModelState.AddModelError("Files", "Must select at least one file");
// TODO: this keeps randomly not being mapable because string->bool binding fails. WHY
if (ModelState.ContainsKey("TermsOfService")) if (ModelState.ContainsKey("TermsOfService"))
ModelState["TermsOfService"].Errors.Clear(); {
ModelState.Remove("TermsOfService");
}
var membershipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext.Current); var membershipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext.Current);
var member = membershipHelper.GetCurrentMember(); var member = membershipHelper.GetCurrentMember();
+2 -1
View File
@@ -22,6 +22,7 @@
<form id="fileupload" action="/Backload/FileHandler" method="POST" enctype="multipart/form-data"> <form id="fileupload" action="/Backload/FileHandler" method="POST" enctype="multipart/form-data">
<h4 class="card-title">Files</h4> <h4 class="card-title">Files</h4>
@Html.Partial("_ValidationField", "Files")
<div class="container-fluid fileupload-buttonbar"> <div class="container-fluid fileupload-buttonbar">
<div class="row"> <div class="row">
<!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload --> <!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
@@ -56,13 +57,13 @@
<!-- The extended global progress state --> <!-- The extended global progress state -->
@*<div class="progress-extended">&nbsp;</div>*@ @*<div class="progress-extended">&nbsp;</div>*@
</div> </div>
@Html.Partial("_ValidationField", "Files")
<!-- The table listing the files available for upload/download --> <!-- The table listing the files available for upload/download -->
<div class="table-responsive card mb-4"> <div class="table-responsive card mb-4">
<table role="presentation" class="table table-sm table-striped mb-0"><tbody class="files"></tbody></table> <table role="presentation" class="table table-sm table-striped mb-0"><tbody class="files"></tbody></table>
</div> </div>
</form> </form>
@using (Html.BeginUmbracoForm<LeafInputController>("Submit", null, new { id = "create" })) @using (Html.BeginUmbracoForm<LeafInputController>("Submit", null, new { id = "create" }))
{ {
@Html.EditorFor(m => m.PhotosynthesisType) @Html.EditorFor(m => m.PhotosynthesisType)
+3 -6
View File
@@ -1,12 +1,9 @@
@model string @model string
@{ @{
var fieldName = Model; var fieldName = Model;
var modelState = ViewData.ModelState[fieldName];
} }
@if (ViewData.ModelState[fieldName] != null @foreach (var error in modelState?.Errors ?? new ModelErrorCollection())
&& ViewData.ModelState[fieldName].Errors.Any())
{ {
foreach (var error in ViewData.ModelState[fieldName].Errors) <div id="@fieldName-error" class="text-danger field-validation-error">@error.ErrorMessage</div>
{
<div id="@fieldName-error" class="is-invalid invalid-feedback">@error.ErrorMessage</div>
}
} }
+2 -1
View File
@@ -11,7 +11,8 @@
"Confirm": function () { "Confirm": function () {
$("#confirmCreate") $("#confirmCreate")
.next(".ui-dialog-buttonpane button:contains('Confirm')") .next(".ui-dialog-buttonpane button:contains('Confirm')")
.attr("disabled", true); .attr("disabled", true)
.addClass("ui-state-disabled");
form.submit(); form.submit();
}, },
"Cancel": function () { "Cancel": function () {