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]
|
[HttpPost]
|
||||||
public ActionResult Submit(LeafInputCreate viewModel)
|
public ActionResult Submit(LeafInputCreate viewModel)
|
||||||
{
|
{
|
||||||
if (!ModelState.IsValid)
|
|
||||||
return CurrentUmbracoPage();
|
|
||||||
|
|
||||||
// directory name is the sessionID
|
// directory name is the sessionID
|
||||||
var files = GetBackloadDirectoryFiles(Session.SessionID);
|
var files = GetBackloadDirectoryFiles(Session.SessionID);
|
||||||
|
|
||||||
|
|||||||
@@ -12,38 +12,31 @@ namespace LeafWeb.WebCms.Utility
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="TModel"></typeparam>
|
/// <typeparam name="TModel"></typeparam>
|
||||||
/// <typeparam name="TProperty"></typeparam>
|
/// <typeparam name="TProperty"></typeparam>
|
||||||
/// <param name="htmlHelper"></param>
|
|
||||||
/// <param name="expression"></param>
|
|
||||||
/// <param name="error"></param>
|
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static MvcHtmlString ValidationErrorFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, string error)
|
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
|
||||||
return new MvcHtmlString(error);
|
HasError(htmlHelper, ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData),ExpressionHelper.GetExpressionText(expression))
|
||||||
else
|
? new MvcHtmlString(error)
|
||||||
return null;
|
: 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);
|
var modelName = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(expression);
|
||||||
FormContext formContext = htmlHelper.ViewContext.FormContext;
|
var formContext = htmlHelper.ViewContext.FormContext;
|
||||||
if (formContext == null)
|
if (formContext == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!htmlHelper.ViewData.ModelState.ContainsKey(modelName))
|
if (!htmlHelper.ViewData.ModelState.ContainsKey(modelName))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ModelState modelState = htmlHelper.ViewData.ModelState[modelName];
|
var modelState = htmlHelper.ViewData.ModelState[modelName];
|
||||||
if (modelState == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
ModelErrorCollection modelErrors = modelState.Errors;
|
var modelErrors = modelState?.Errors;
|
||||||
if (modelErrors == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return (modelErrors.Count > 0);
|
return modelErrors?.Count > 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
@using ClientDependency.Core.Mvc
|
@using ClientDependency.Core.Mvc
|
||||||
@using LeafWeb.WebCms.Controllers
|
@using LeafWeb.WebCms.Controllers
|
||||||
@model LeafWeb.WebCms.Models.LeafInputCreate
|
@model LeafInputCreate
|
||||||
@{
|
@{
|
||||||
Html.RequiresCss("~/backload/blueimp/bootstrap/BasicPlusUI/css");
|
Html.RequiresCss("~/backload/blueimp/bootstrap/BasicPlusUI/css");
|
||||||
Html.RequiresJs("~/scripts/jquery.autocomplete.min.js");
|
Html.RequiresJs("~/scripts/jquery.autocomplete.min.js", 2);
|
||||||
Html.RequiresJs("~/scripts/jquery.validate.min.js");
|
Html.RequiresJs("~/scripts/jquery.validate.min.js", 2);
|
||||||
Html.RequiresJs("~/scripts/jquery.validate.unobtrusive.min.js");
|
Html.RequiresJs("~/scripts/jquery.validate.unobtrusive.min.js", 2);
|
||||||
Html.RequiresJs("~/scripts/jquery.validate.unobtrusive.bootstrap.min.js");
|
Html.RequiresJs("~/scripts/jquery.validate.unobtrusive.bootstrap.min.js", 2);
|
||||||
Html.RequiresJs("~/scripts/LeafInputCreate.js");
|
Html.RequiresJs("~/scripts/jquery.validate.custom.js", 2);
|
||||||
|
Html.RequiresJs("~/scripts/LeafInputCreate.js", 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
Html.RequiresJs("~/scripts/jquery-1.12.4.js", 0);
|
Html.RequiresJs("~/scripts/jquery-1.12.4.js", 0);
|
||||||
Html.RequiresJs("~/scripts/bootstrap.js", 0);
|
Html.RequiresJs("~/scripts/bootstrap.js", 0);
|
||||||
Html.RequiresJs("~/scripts/jquery-ui-1.12.1.js", 1);
|
Html.RequiresJs("~/scripts/jquery-ui-1.12.1.js", 1);
|
||||||
Html.RequiresJs("~/scripts/site.js", 2);
|
Html.RequiresJs("~/scripts/site.js", 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
@model LeafWeb.WebCms.Models.SelectListViewModel
|
@model SelectListViewModel
|
||||||
@{
|
@{
|
||||||
Layout = "~/Views/Shared/EditorTemplates/_FieldLayout.cshtml";
|
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.bootstrap.min.js" />
|
||||||
<Content Include="scripts\jquery.validate.unobtrusive.js" />
|
<Content Include="scripts\jquery.validate.unobtrusive.js" />
|
||||||
<Content Include="scripts\jquery.validate.unobtrusive.min.js" />
|
<Content Include="scripts\jquery.validate.unobtrusive.min.js" />
|
||||||
|
<Content Include="scripts\jquery.validate.custom.js" />
|
||||||
<Content Include="scripts\LeafInputCreate.js" />
|
<Content Include="scripts\LeafInputCreate.js" />
|
||||||
<Content Include="Views\Web.config" />
|
<Content Include="Views\Web.config" />
|
||||||
<Content Include="Views\Partials\Grid\Editors\Textstring.cshtml" />
|
<Content Include="Views\Partials\Grid\Editors\Textstring.cshtml" />
|
||||||
|
|||||||
@@ -1,12 +1,6 @@
|
|||||||
function initFileUpload(objectContext) {
|
function initFileUpload(objectContext) {
|
||||||
"use strict";
|
"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 =
|
$("form#create").data("validator").settings.submitHandler =
|
||||||
function (form) {
|
function (form) {
|
||||||
var identifier = $(form).find("input[name='Identifier']").val();
|
var identifier = $(form).find("input[name='Identifier']").val();
|
||||||
|
|||||||
@@ -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