diff --git a/src/QuickForm/Attributes/HiddenAttribute.cs b/src/QuickForm/Attributes/HiddenAttribute.cs new file mode 100644 index 0000000..8c73a51 --- /dev/null +++ b/src/QuickForm/Attributes/HiddenAttribute.cs @@ -0,0 +1,9 @@ +namespace QuickForm.Attributes; + +/// +/// For attributes that have an input field, but should not be displayed. +/// +[AttributeUsage(AttributeTargets.Property)] +public class HiddenAttribute : Attribute +{ +} diff --git a/src/QuickForm/Attributes/IgnoreAttribute.cs b/src/QuickForm/Attributes/IgnoreAttribute.cs new file mode 100644 index 0000000..ad96572 --- /dev/null +++ b/src/QuickForm/Attributes/IgnoreAttribute.cs @@ -0,0 +1,9 @@ +namespace QuickForm.Attributes; + +/// +/// For attributes that don't have NotMapped, but still need to be ignored. +/// +[AttributeUsage(AttributeTargets.Property)] +public class IgnoreAttribute : Attribute +{ +} diff --git a/src/QuickForm/Components/IQuickFormField.cs b/src/QuickForm/Components/IQuickFormField.cs index b7de566..1ce5179 100644 --- a/src/QuickForm/Components/IQuickFormField.cs +++ b/src/QuickForm/Components/IQuickFormField.cs @@ -42,4 +42,12 @@ public interface IQuickFormField /// the string parameter is the class to be applied to the input element. /// public RenderFragment ValidationMessages { get; } + + /// + /// Gets if the input together with its label and everything else should be hidden. + /// + /// + /// The input element will still be rendered, but it will be hidden. + /// + public bool IsHidden { get; } } \ No newline at end of file diff --git a/src/QuickForm/Components/QuickForm.razor b/src/QuickForm/Components/QuickForm.razor index c9f95fe..b576030 100644 --- a/src/QuickForm/Components/QuickForm.razor +++ b/src/QuickForm/Components/QuickForm.razor @@ -18,7 +18,16 @@ @foreach (var field in Fields) { - @ChildContent(field) + if (field.IsHidden) + { +
+ @ChildContent(field) +
+ } + else + { + @ChildContent(field) + } } @if (SubmitButtonTemplate is not null) diff --git a/src/QuickForm/Components/QuickFormField.cs b/src/QuickForm/Components/QuickFormField.cs index dc7060a..5e73665 100644 --- a/src/QuickForm/Components/QuickFormField.cs +++ b/src/QuickForm/Components/QuickFormField.cs @@ -2,6 +2,7 @@ using System.Reflection; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Forms; +using QuickForm.Attributes; using QuickForm.Internal; namespace QuickForm.Components; @@ -19,6 +20,8 @@ internal sealed class QuickFormField : IQuickFormField public string? ValidFeedback => PropertyInfo.ValidFeedbackText(); + public bool IsHidden => PropertyInfo.GetCustomAttribute() is not null; + public RenderFragment InputComponent { get @@ -142,6 +145,7 @@ internal static IEnumerable> FromForm(QuickForm return typeof(TEntity) .GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy) .Where(prop => prop.GetCustomAttribute() is null) + .Where(prop => prop.GetCustomAttribute() is null) .Select(prop => new QuickFormField(form, prop)); } } \ No newline at end of file diff --git a/test/QuickForm.Example/Properties/launchSettings.json b/test/QuickForm.Example/Properties/launchSettings.json index 910ff88..b0e6dfe 100644 --- a/test/QuickForm.Example/Properties/launchSettings.json +++ b/test/QuickForm.Example/Properties/launchSettings.json @@ -1,13 +1,14 @@ -{ +{ "profiles": { "https": { - "commandName": "Project", - "dotnetRunMessages": true, - "launchBrowser": false, - "applicationUrl": "https://localhost:443;http://localhost:80", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", + "applicationUrl": "https://localhost:443;http://localhost:80", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } } } -} +} \ No newline at end of file