Input fields represent data that users provide to a form. They are properties on the request class decorated with InputFieldAttribute. The framework uses reflection to discover these properties and generates metadata that tells the client how to render them.
public class InputFieldAttribute : FieldAttribute{ public InputFieldAttribute() : base(MetadataBinder.ComponentCategories.Input) { } public bool Required { get; set; }}
public abstract class FieldAttribute : Attribute{ public bool Hidden { get; set; } public string? Label { get; set; } public int OrderIndex { get; set; }}
Hides the field from the UI. Useful for internal values:
public class Request : IRequest<Response>{ [InputField(Label = "Username")] public string Username { get; set; } [InputField(Hidden = true)] public int TenantId { get; set; } // Not visible to user}
Hidden fields are still included in the metadata but marked as not visible.
public class ColorPickerBinding : ComponentBinding{ public ColorPickerBinding() : base( MetadataBinder.ComponentCategories.Input, serverType: typeof(Color), componentType: "color-picker", metadataFactory: null) { }}// Register the bindingbinder.Inputs.Bindings.AddBinding(new ColorPickerBinding());// Use in your formpublic class Request : IRequest<Response>{ [InputField(Label = "Theme Color")] public Color ThemeColor { get; set; }}
The framework will now map Color properties to the "color-picker" component.
public class FieldMetadata{ public string? Id { get; set; } public string? Label { get; set; } public int OrderIndex { get; set; } public bool Hidden { get; set; } public Component Component { get; set; } public object? Configuration { get; set; } public IDictionary<string, object?>? CustomProperties { get; set; } public IList<EventHandlerMetadata>? EventHandlers { get; set; }}
This metadata is serialized to JSON and sent to the client:
public class RegisterUser : Form<Request, Response>{ protected override Response Handle(Request request) { if (string.IsNullOrWhiteSpace(request.Email)) { throw new BusinessException("Email is required"); } if (!IsValidEmail(request.Email)) { throw new BusinessException("Invalid email format"); } // Process registration... }}
Never trust client-side validation alone. Always validate and sanitize data on the server.