Form quick fixes (#4759)

This commit is contained in:
Andrew Camilleri 2023-03-15 10:23:33 +01:00 committed by GitHub
parent 06d7483ca3
commit e344622c9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 6 deletions

View File

@ -50,7 +50,7 @@ public class Form
HashSet<string> nameReturned = new();
foreach (var f in GetAllFieldsCore(new List<string>(), Fields))
{
var fullName = string.Join('_', f.Path);
var fullName = string.Join('_', f.Path.Where(s => !string.IsNullOrEmpty(s)));
if (!nameReturned.Add(fullName))
continue;
yield return (fullName, f.Path, f.Field);
@ -63,7 +63,7 @@ public class Form
HashSet<string> nameReturned = new();
foreach (var f in GetAllFieldsCore(new List<string>(), Fields))
{
var fullName = string.Join('_', f.Path);
var fullName = string.Join('_', f.Path.Where(s => !string.IsNullOrEmpty(s)));
if (!nameReturned.Add(fullName))
{
errors.Add($"Form contains duplicate field names '{fullName}'");
@ -128,8 +128,8 @@ public class Form
}
else if (prop.Value.Type == JTokenType.String)
{
var fullname = String.Join('_', propPath);
if (fields.TryGetValue(fullname, out var f) && !f.Constant)
var fullName = string.Join('_', propPath.Where(s => !string.IsNullOrEmpty(s)));
if (fields.TryGetValue(fullName, out var f) && !f.Constant)
f.Value = prop.Value.Value<string>();
}
}

View File

@ -10,7 +10,7 @@
{
if (FormComponentProviders.TypeToComponentProvider.TryGetValue(field.Type, out var partial))
{
field.Name = $"{Model.Name}_{field.Name}";
field.Name = $"{(string.IsNullOrEmpty(Model.Name)? string.Empty: $"{Model.Name}_")}{field.Name}";
<partial name="@partial.View" for="@field"></partial>
}
}

View File

@ -21,6 +21,8 @@
<span class="text-danger" data-valmsg-for="@Model.Name" data-valmsg-replace="true">@(isInvalid && errors.Any() ? errors.First().ErrorMessage : string.Empty)</span>
@if (!string.IsNullOrEmpty(Model.HelpText))
{
<div id="@($"HelpText-{Model.Name}")" class="form-text">@Model.HelpText</div>
<div id="@($"HelpText-{Model.Name}")" class="form-text">
@Safe.Raw(Model.HelpText)
</div>
}
</div>