Customization
While being effortless to use, QuickForm is flexible enough to support a wide variety of customization.
There are a few ways to customize QuickForm:
- Using attributes: To decorate the individual fields and their looks.
- Customizing the whole layout: To create a custom QuickForm component with a custom layout and custom styles + any additional parameters you may need
Custom layout
This is a step-by-step guide to creating a custom form styled with TailwindCSS.
Please note, that this process may seem a little complex for users who are not familiar with Blazor.
Define the directives
AppForm.razor - declaring directives | |
---|---|
- The
@inherits
directive is used to specify the base class for this component. - The
@typeparam
directive is used to specify that the component will be generic and work with any type.
Create the layouts
-
The markup inside the
ChildContent
fragment, will be applied to individual fields. The@context
object is used to access the field's metadata and the input component. It is an IQuickFormField object. -
@context.EditorId
is a string, which holds the id of the input field. This can be used to associate the label with the input field. It is automatically generated. -
@context.DisplayName
is a string, which holds the display name for the field. This can be set using the[DisplayName]
or[Display(Name = ...)]
attribute. -
@context.InputComponent
is a RenderFragment<string> that renders the input field.
The string parameter for this RenderFragment is the CSS class to be applied to the input field. -
@context.Description
is a string, which holds the description for the field. This can be set using the[Description]
or[Display(Description = ...)]
attribute. -
@context.ValidFeedback
is a string, which holds the valid feedback for the field. This can be set using the[ValidFeedback]
attribute. -
Just like the
@context.InputComponent
,@context.ValidationMessages
is also a RenderFragment<string> that renders the validation messages.
The string parameter for this RenderFragment is the CSS class to be applied to the container element containing validation messages.
@context
See IQuickFormField interface for more information on the @context
object and what fields are available to you.
Important! add the base component's markup
- This line is used to call your custom component's base class's - QuickForm's
BuildRenderTree
method.
Important
This is necessary to render the form and its fields. Without this line your form will not be rendered.
Congratulations!
You can now use your component all around your application!
Here is what the output should look like:
As an exercise to get better with using the library, try creating a component for a different CSS framework, or even a custom one!