Skip to content

Commit

Permalink
fix(HtmlTags): Remove conflict between hidden id and int editors
Browse files Browse the repository at this point in the history
  • Loading branch information
mycroes committed Aug 29, 2024
1 parent b2d3777 commit 2cfe160
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using HtmlTags;
using HtmlTags.Conventions;

Expand All @@ -19,7 +18,7 @@ public SupportManagerHtmlConventions()
.AddPlaceholder("MM/DD/YYYY")
.AddClass("datepicker")
.Value(m.Value<DateTime?>() != null ? m.Value<DateTime>().ToShortDateString() : string.Empty));
Editors.If(er => er.Accessor.Name.EndsWith("id", StringComparison.OrdinalIgnoreCase)).BuildBy(a => new HiddenTag().Value(a.StringValue()));

Editors.IfPropertyIs<byte[]>().BuildBy(a => new HiddenTag().Value(Convert.ToBase64String(a.Value<byte[]>())));

Editors.IfPropertyTypeIs(t => (Nullable.GetUnderlyingType(t) ?? t) == typeof(TimeSpan)).ModifyWith(m =>
Expand All @@ -31,8 +30,16 @@ public SupportManagerHtmlConventions()
m.CurrentTag.Attr("type", "date")
.Value(m.Value<DateOnly?>() is { } date ? date.ToString("O") : string.Empty));

Editors.IfPropertyTypeIs(t => (Nullable.GetUnderlyingType(t) ?? t) == typeof(int))
.ModifyWith(m => m.CurrentTag.Attr("type", "number").Attr("step", "1"));
Editors.IfPropertyTypeIs(t => (Nullable.GetUnderlyingType(t) ?? t) == typeof(int)).ModifyWith(m =>
{
if ("input".Equals(m.CurrentTag.Attr("type")))
{
m.CurrentTag.Attr("type", "number").Attr("step", "1");
}
});

Editors.If(er => er.Accessor.Name.EndsWith("id", StringComparison.OrdinalIgnoreCase))
.BuildBy(a => new HiddenTag().Value(a.StringValue()));

Editors.BuilderPolicy<UserPhoneNumberSelectElementBuilder>();
Editors.BuilderPolicy<TeamSelectElementBuilder>();
Expand Down

0 comments on commit 2cfe160

Please sign in to comment.