From eab649325281b1688790128012e64631ed30430a Mon Sep 17 00:00:00 2001 From: maliming Date: Thu, 25 Apr 2019 21:01:33 +0800 Subject: [PATCH] fix #1051 new/edit post jquery validate problem. --- .../Volo.Blogging.Web/Pages/Blog/BloggingPage.cs | 5 +++++ .../src/Volo.Blogging.Web/Pages/Blog/Posts/edit.js | 14 ++++++++++++-- .../src/Volo.Blogging.Web/Pages/Blog/Posts/new.js | 14 +++++++++++--- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/BloggingPage.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/BloggingPage.cs index 03214d1ee3..88133e0e84 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/BloggingPage.cs +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/BloggingPage.cs @@ -55,6 +55,11 @@ namespace Volo.Blogging.Pages.Blog public IHtmlContent RenderMarkdownToHtml(string content) { + if(content.IsNullOrWhiteSpace()) + { + return new HtmlString(""); + } + byte[] bytes = Encoding.Default.GetBytes(content); var utf8Content = Encoding.UTF8.GetString(bytes); diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/edit.js b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/edit.js index 9fb4929d30..6b0dd9f02b 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/edit.js +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/edit.js @@ -1,4 +1,4 @@ -(function ($) { +$(function () { var $container = $("#edit-post-container"); var $editorContainer = $container.find(".edit-post-editor"); @@ -72,6 +72,8 @@ load: function () { $editorContainer.find(".loading-cover").remove(); $submitButton.prop("disabled", false); + $form.data("validator").settings.ignore = '.ignore'; + $editorContainer.find(':input').addClass('ignore'); } } }).data(editorDataKey); @@ -82,8 +84,16 @@ var postText = newPostEditor.getMarkdown(); $postTextInput.val(postText); + if (!$form.valid()) { + var validationResult = $form.validate(); + abp.message.warn(validationResult.errorList[0].message); //TODO: errors can be merged into lines. make sweetalert accept HTML. + e.preventDefault(); + return false; //for old browsers + } + $submitButton.buttonBusy(); $(this).off('submit').submit(); }); -})(jQuery); +}); + diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/new.js b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/new.js index 519d3f41f4..0c3e927264 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/new.js +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/new.js @@ -1,5 +1,4 @@ -var editor = null; -(function ($) { +$(function () { var $container = $("#qa-new-post-container"); var $editorContainer = $container.find(".new-post-editor"); @@ -72,6 +71,8 @@ load: function () { $editorContainer.find(".loading-cover").remove(); $submitButton.prop("disabled", false); + $form.data("validator").settings.ignore = '.ignore'; + $editorContainer.find(':input').addClass('ignore'); } } }).data(editorDataKey); @@ -82,6 +83,13 @@ var postText = newPostEditor.getMarkdown(); $postTextInput.val(postText); + if (!$form.valid()) { + var validationResult = $form.validate(); + abp.message.warn(validationResult.errorList[0].message); //TODO: errors can be merged into lines. make sweetalert accept HTML. + e.preventDefault(); + return false; //for old browsers + } + $submitButton.buttonBusy(); $(this).off('submit').submit(); }); @@ -113,4 +121,4 @@ } }); -})(jQuery); +});