From 3b5115392603cdeee91d70e7b288cd2d3e380f67 Mon Sep 17 00:00:00 2001 From: Ahmet Date: Thu, 4 Feb 2021 16:17:30 +0300 Subject: [PATCH 1/2] Added validations to author create & edit modals --- docs/en/Tutorials/Part-9.md | 176 +++++++++++++++++++++++------------- 1 file changed, 114 insertions(+), 62 deletions(-) diff --git a/docs/en/Tutorials/Part-9.md b/docs/en/Tutorials/Part-9.md index a1b4b03e21..d416052260 100644 --- a/docs/en/Tutorials/Part-9.md +++ b/docs/en/Tutorials/Part-9.md @@ -843,8 +843,10 @@ Create a new Razor Component Page, `/Pages/Authors.razor`, in the `Acme.BookStor ````xml @page "/authors" @using Acme.BookStore.Authors +@using Acme.BookStore.Localization @inherits BookStoreComponentBase @inject IAuthorAppService AuthorAppService +@inject AbpBlazorMessageLocalizerHelper LH @@ -917,68 +919,104 @@ Create a new Razor Component Page, `/Pages/Authors.razor`, in the `Acme.BookStor - - @L["NewAuthor"] - - - - - @L["Name"] - - - - @L["BirthDate"] - - - - @L["ShortBio"] - - - - - - - +
+ + @L["NewAuthor"] + + + + + + + @L["Name"] + + + + + + + + + @L["BirthDate"] + + + + + @L["ShortBio"] + + + + + + + + + + + + + +
- - @EditingAuthor.Name - - - - - @L["Name"] - - - - @L["BirthDate"] - - - - @L["ShortBio"] - - - - - - - +
+ + @EditingAuthor.Name + + + + + + + @L["Name"] + + + + + + + + + @L["BirthDate"] + + + + + @L["ShortBio"] + + + + + + + + + + + + + +
```` @@ -1025,6 +1063,10 @@ namespace Acme.BookStore.Blazor.Pages private Modal CreateAuthorModal { get; set; } private Modal EditAuthorModal { get; set; } + private Validations CreateValidationsRef; + + private Validations EditValidationsRef; + public Authors() { NewAuthor = new CreateAuthorDto(); @@ -1079,6 +1121,8 @@ namespace Acme.BookStore.Blazor.Pages private void OpenCreateAuthorModal() { + CreateValidationsRef?.ClearAll(); + NewAuthor = new CreateAuthorDto(); CreateAuthorModal.Show(); } @@ -1090,6 +1134,8 @@ namespace Acme.BookStore.Blazor.Pages private void OpenEditAuthorModal(AuthorDto author) { + EditValidationsRef?.ClearAll(); + EditingAuthorId = author.Id; EditingAuthor = ObjectMapper.Map(author); EditAuthorModal.Show(); @@ -1114,16 +1160,22 @@ namespace Acme.BookStore.Blazor.Pages private async Task CreateAuthorAsync() { - await AuthorAppService.CreateAsync(NewAuthor); - await GetAuthorsAsync(); - CreateAuthorModal.Hide(); + if (CreateValidationsRef?.ValidateAll() ?? true) + { + await AuthorAppService.CreateAsync(NewAuthor); + await GetAuthorsAsync(); + CreateAuthorModal.Hide(); + } } private async Task UpdateAuthorAsync() { - await AuthorAppService.UpdateAsync(EditingAuthorId, EditingAuthor); - await GetAuthorsAsync(); - EditAuthorModal.Hide(); + if (EditValidationsRef?.ValidateAll() ?? true) + { + await AuthorAppService.UpdateAsync(EditingAuthorId, EditingAuthor); + await GetAuthorsAsync(); + EditAuthorModal.Hide(); + } } } } From 6fd1a0267cd528f2ba1b174486430a8efc8d1bc7 Mon Sep 17 00:00:00 2001 From: Ahmet Date: Tue, 9 Feb 2021 14:45:11 +0300 Subject: [PATCH 2/2] remove not necessary nullable check from blazor validation --- docs/en/Tutorials/Part-9.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/en/Tutorials/Part-9.md b/docs/en/Tutorials/Part-9.md index d416052260..c623cfcf46 100644 --- a/docs/en/Tutorials/Part-9.md +++ b/docs/en/Tutorials/Part-9.md @@ -1121,7 +1121,7 @@ namespace Acme.BookStore.Blazor.Pages private void OpenCreateAuthorModal() { - CreateValidationsRef?.ClearAll(); + CreateValidationsRef.ClearAll(); NewAuthor = new CreateAuthorDto(); CreateAuthorModal.Show(); @@ -1134,7 +1134,7 @@ namespace Acme.BookStore.Blazor.Pages private void OpenEditAuthorModal(AuthorDto author) { - EditValidationsRef?.ClearAll(); + EditValidationsRef.ClearAll(); EditingAuthorId = author.Id; EditingAuthor = ObjectMapper.Map(author); @@ -1160,7 +1160,7 @@ namespace Acme.BookStore.Blazor.Pages private async Task CreateAuthorAsync() { - if (CreateValidationsRef?.ValidateAll() ?? true) + if (CreateValidationsRef.ValidateAll()) { await AuthorAppService.CreateAsync(NewAuthor); await GetAuthorsAsync(); @@ -1170,7 +1170,7 @@ namespace Acme.BookStore.Blazor.Pages private async Task UpdateAuthorAsync() { - if (EditValidationsRef?.ValidateAll() ?? true) + if (EditValidationsRef.ValidateAll()) { await AuthorAppService.UpdateAsync(EditingAuthorId, EditingAuthor); await GetAuthorsAsync();