8 |
Welcome to validation
9 |
I explored different validation in Razor Pages and how they could be fit together with htmx
10 |
11 |
12 | - Unobtrusive - jquery-3.3.2.js + jquery.validate.js + jquery.validate.unobtrusive.js validation, built in into ASP.NET and Razor Pages and used by default.
13 | - HTML5 - built-in HTML validation available by default.
14 | - Unobtrusive + Htmx - jquery.validate.unobtrusive.js validation attached to htmx.
15 | - HTML5 + Htmx - built-in HTML validation used with htmx.
16 | - HTML5 + Hypermedia + Htmx - a hypermedia-friendly way for HTML5 form validation
17 |
18 |
--------------------------------------------------------------------------------
/Xakpc.RazorHtmx.Validation/wwwroot/lib/jquery/LICENSE.txt:
--------------------------------------------------------------------------------
1 |
2 | Copyright OpenJS Foundation and other contributors, https://openjsf.org/
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining
5 | a copy of this software and associated documentation files (the
6 | "Software"), to deal in the Software without restriction, including
7 | without limitation the rights to use, copy, modify, merge, publish,
8 | distribute, sublicense, and/or sell copies of the Software, and to
9 | permit persons to whom the Software is furnished to do so, subject to
10 | the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/Xakpc.RazorHtmx.Validation/TagHelpers/StringLengthExInputTagHelper.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Mvc.ViewFeatures;
2 | using Microsoft.AspNetCore.Razor.TagHelpers;
3 | using System.ComponentModel.DataAnnotations;
4 |
5 | namespace Xakpc.RazorHtmx.Validation.TagHelpers;
6 |
7 | [HtmlTargetElement("input", Attributes = "asp-for")]
8 | public class StringLengthExInputTagHelper : TagHelper
9 | {
10 | [HtmlAttributeName("asp-for")]
11 | public ModelExpression For { get; set; }
12 |
13 | public override void Process(TagHelperContext context, TagHelperOutput output)
14 | {
15 | var attribute = For.ModelExplorer.Metadata.ValidatorMetadata.FirstOrDefault(
16 | attr => attr is StringLengthAttribute) as StringLengthAttribute;
17 |
18 | if (attribute != null)
19 | {
20 | if (attribute.MinimumLength > 0)
21 | {
22 | output.Attributes.SetAttribute("minlength", attribute.MinimumLength);
23 | }
24 |
25 | if (!string.IsNullOrEmpty(attribute.ErrorMessage))
26 | {
27 | output.Attributes.SetAttribute("data-err-length", attribute.ErrorMessage);
28 | }
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/Xakpc.RazorHtmx.Validation/wwwroot/lib/jquery-validation/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 | =====================
3 |
4 | Copyright Jörn Zaefferer
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/Xakpc.RazorHtmx.Validation/wwwroot/lib/jquery-validation-unobtrusive/LICENSE.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) .NET Foundation and Contributors
4 |
5 | All rights reserved.
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy
8 | of this software and associated documentation files (the "Software"), to deal
9 | in the Software without restriction, including without limitation the rights
10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | copies of the Software, and to permit persons to whom the Software is
12 | furnished to do so, subject to the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be included in all
15 | copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 | SOFTWARE.
24 |
--------------------------------------------------------------------------------
/Xakpc.RazorHtmx/Pages/BulkUpdate/BulkUpdate.cshtml:
--------------------------------------------------------------------------------
1 | @page "/bulk-update"
2 | @model BulkUpdateModel
3 |
4 |