Fix validation for Terms of Service
This commit is contained in:
@@ -1 +1 @@
|
||||
C:\Users\poprhythm\AppData\Local\Temp\Temporary ASP.NET Files\vs\f80e29bb\faae20bf\App_Web_all.generated.cs.8f9494c4.eej8t44r.dll
|
||||
C:\Users\poprhythm\AppData\Local\Temp\Temporary ASP.NET Files\vs\f80e29bb\faae20bf\App_Web_all.generated.cs.8f9494c4.uciyyxfl.dll
|
||||
@@ -27,9 +27,6 @@ namespace LeafWeb.WebCms.Controllers
|
||||
[HttpPost]
|
||||
public ActionResult Submit(LeafInputCreate viewModel)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
return CurrentUmbracoPage();
|
||||
|
||||
// directory name is the sessionID
|
||||
var files = GetBackloadDirectoryFiles(Session.SessionID);
|
||||
|
||||
|
||||
@@ -12,38 +12,31 @@ namespace LeafWeb.WebCms.Utility
|
||||
/// </summary>
|
||||
/// <typeparam name="TModel"></typeparam>
|
||||
/// <typeparam name="TProperty"></typeparam>
|
||||
/// <param name="htmlHelper"></param>
|
||||
/// <param name="expression"></param>
|
||||
/// <param name="error"></param>
|
||||
/// <returns></returns>
|
||||
public static MvcHtmlString ValidationErrorFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, string error)
|
||||
{
|
||||
if (HasError(htmlHelper, ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData),ExpressionHelper.GetExpressionText(expression)))
|
||||
return new MvcHtmlString(error);
|
||||
else
|
||||
return null;
|
||||
return
|
||||
HasError(htmlHelper, ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData),ExpressionHelper.GetExpressionText(expression))
|
||||
? new MvcHtmlString(error)
|
||||
: null;
|
||||
}
|
||||
|
||||
|
||||
private static bool HasError(this HtmlHelper htmlHelper, ModelMetadata modelMetadata, string expression)
|
||||
private static bool HasError(this HtmlHelper htmlHelper, ModelMetadata modelMetadata, string expression)
|
||||
{
|
||||
string modelName = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(expression);
|
||||
FormContext formContext = htmlHelper.ViewContext.FormContext;
|
||||
var modelName = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(expression);
|
||||
var formContext = htmlHelper.ViewContext.FormContext;
|
||||
if (formContext == null)
|
||||
return false;
|
||||
|
||||
if (!htmlHelper.ViewData.ModelState.ContainsKey(modelName))
|
||||
return false;
|
||||
|
||||
ModelState modelState = htmlHelper.ViewData.ModelState[modelName];
|
||||
if (modelState == null)
|
||||
return false;
|
||||
var modelState = htmlHelper.ViewData.ModelState[modelName];
|
||||
|
||||
ModelErrorCollection modelErrors = modelState.Errors;
|
||||
if (modelErrors == null)
|
||||
return false;
|
||||
var modelErrors = modelState?.Errors;
|
||||
|
||||
return (modelErrors.Count > 0);
|
||||
return modelErrors?.Count > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
@using ClientDependency.Core.Mvc
|
||||
@using LeafWeb.WebCms.Controllers
|
||||
@model LeafWeb.WebCms.Models.LeafInputCreate
|
||||
@model LeafInputCreate
|
||||
@{
|
||||
Html.RequiresCss("~/backload/blueimp/bootstrap/BasicPlusUI/css");
|
||||
Html.RequiresJs("~/scripts/jquery.autocomplete.min.js");
|
||||
Html.RequiresJs("~/scripts/jquery.validate.min.js");
|
||||
Html.RequiresJs("~/scripts/jquery.validate.unobtrusive.min.js");
|
||||
Html.RequiresJs("~/scripts/jquery.validate.unobtrusive.bootstrap.min.js");
|
||||
Html.RequiresJs("~/scripts/LeafInputCreate.js");
|
||||
Html.RequiresJs("~/scripts/jquery.autocomplete.min.js", 2);
|
||||
Html.RequiresJs("~/scripts/jquery.validate.min.js", 2);
|
||||
Html.RequiresJs("~/scripts/jquery.validate.unobtrusive.min.js", 2);
|
||||
Html.RequiresJs("~/scripts/jquery.validate.unobtrusive.bootstrap.min.js", 2);
|
||||
Html.RequiresJs("~/scripts/jquery.validate.custom.js", 2);
|
||||
Html.RequiresJs("~/scripts/LeafInputCreate.js", 3);
|
||||
}
|
||||
|
||||
<div class="container">
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
Html.RequiresJs("~/scripts/jquery-1.12.4.js", 0);
|
||||
Html.RequiresJs("~/scripts/bootstrap.js", 0);
|
||||
Html.RequiresJs("~/scripts/jquery-ui-1.12.1.js", 1);
|
||||
Html.RequiresJs("~/scripts/site.js", 2);
|
||||
Html.RequiresJs("~/scripts/site.js", 3);
|
||||
}
|
||||
|
||||
<!DOCTYPE html>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@model LeafWeb.WebCms.Models.SelectListViewModel
|
||||
@model SelectListViewModel
|
||||
@{
|
||||
Layout = "~/Views/Shared/EditorTemplates/_FieldLayout.cshtml";
|
||||
}
|
||||
|
||||
@@ -763,6 +763,7 @@
|
||||
<Content Include="scripts\jquery.validate.unobtrusive.bootstrap.min.js" />
|
||||
<Content Include="scripts\jquery.validate.unobtrusive.js" />
|
||||
<Content Include="scripts\jquery.validate.unobtrusive.min.js" />
|
||||
<Content Include="scripts\jquery.validate.custom.js" />
|
||||
<Content Include="scripts\LeafInputCreate.js" />
|
||||
<Content Include="Views\Web.config" />
|
||||
<Content Include="Views\Partials\Grid\Editors\Textstring.cshtml" />
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
function initFileUpload(objectContext) {
|
||||
"use strict";
|
||||
|
||||
// enforcetrue attribute client support
|
||||
jQuery.validator.addMethod("enforcetrue", function (value, element, param) {
|
||||
return element.checked;
|
||||
});
|
||||
jQuery.validator.unobtrusive.adapters.addBool("enforcetrue");
|
||||
|
||||
$("form#create").data("validator").settings.submitHandler =
|
||||
function (form) {
|
||||
var identifier = $(form).find("input[name='Identifier']").val();
|
||||
@@ -20,7 +14,7 @@
|
||||
$(this).dialog("close");
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// We use the upload handler integrated into Backload:
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// enforcetrue attribute client support
|
||||
jQuery.validator.addMethod("enforcetrue",
|
||||
function(value, element) {
|
||||
return element.checked;
|
||||
});
|
||||
jQuery.validator.unobtrusive.adapters.addBool("enforcetrue");
|
||||
Reference in New Issue
Block a user