Form
High performance Form component with data scope management. Including data collection, verification, and styles.
When to use
- When you need to create an instance or collect information.
- When you need to validate fields in certain rules.
Examples
Form API#
| Property | Description | Type | Default Value |
|---|---|---|---|
| RequiredMark | ParameterChange how required/optional field labels are displayed on the form.
|
FormRequiredMark | -- |
| Layout | ParameterLayout of form items in the form | FormLayout | FormLayout.Horizontal |
| ChildContent | ParameterContent of the form. Typically contains different form inputs and layout elements. | RenderFragment<TModel> | -- |
| LabelCol | ParameterControl the layout of the label. Commonly used to set widths for different screen sizes. | ColLayoutParam | -- |
| LabelAlign | ParameterAlign the label to the left or right | AntLabelAlignType? | -- |
| LabelColSpan | ParameterGets/sets the Span property on AntDesign.Form`1.LabelCol. |
OneOf<String, Int32> | -- |
| LabelColOffset | ParameterGets/sets the Offset property on AntDesign.Form`1.LabelCol. |
OneOf<String, Int32> | -- |
| WrapperCol | ParameterControl the layout of the input element's wrapper. Commonly used to set widths for different screen sizes. | ColLayoutParam | -- |
| WrapperColSpan | ParameterGets/sets the Span property on AntDesign.Form`1.WrapperCol. |
OneOf<String, Int32> | -- |
| WrapperColOffset | ParameterGets/sets the Offset property on AntDesign.Form`1.WrapperColOffset. |
OneOf<String, Int32> | -- |
| Size | ParameterThe size of the ant components inside the form | FormSize? | -- |
| Name | ParameterGets or sets the form handler name. This is required for posting it to a server-side endpoint. Or using for get the form instance from FormProviderFinishEventArgs. |
String | -- |
| Method | ParameterHttp method used to submit form | HttpMethod | -- |
| Model | ParameterThe model to bind the form inputs to | TModel | -- |
| Loading | ParameterIf the form is loading or not | Boolean | false |
| OnFinish | ParameterCallback executed when the form is submitted and PASSES validation. | EventCallback<EditContext> | -- |
| OnFinishFailed | ParameterCallback executed when the form is submitted and FAILS validation. | EventCallback<EditContext> | -- |
| OnFieldChanged | ParameterCallback executed when a field inside the form changes | EventCallback<FieldChangedEventArgs> | -- |
| OnValidationRequested | ParameterCallback executed when validation is requested | EventCallback<ValidationRequestedEventArgs> | -- |
| OnValidationStateChanged | ParameterCallback executed when the validation changes | EventCallback<ValidationStateChangedEventArgs> | -- |
| Validator | ParameterValidator to use in the form. Used when AntDesign.Form`1.ValidateMode is FormValidateMode.Default or FormValidateMode.Complex |
RenderFragment | -- |
| ValidateOnChange | ParameterEnable validation when component values change | Boolean | -- |
| ValidateMode | ParameterWhich mode of validation the form should useWill use both attributes and rules in the same time. Obsolete Will be removed in a future version. |
FormValidateMode | FormValidateMode.Complex |
| Enhance | ParameterIf enabled, form submission is performed without fully reloading the page. This is equivalent to adding data-enhance to the form. | Boolean | -- |
| Autocomplete | ParameterWhether input elements can by default have their values automatically completed by the browser | String | -- |
| Locale | ParameterThe localization options | FormLocale | -- |
| IsModified | A flag indicating if the form has been modified | Boolean | -- |
| EditContext | Get the AntDesign.Form`1.EditContext instance inner the form |
EditContext | -- |
| Id | ParameterID for the component's HTML | String | Uniquely Generated ID |
| Class | ParameterSpecifies one or more class names for an DOM element. | String | -- |
| Style | ParameterSpecifies an inline style for a DOM element. | String | -- |
| RefBack | ParameterA ForwardRef instance. You can get a reference to the internal DOM by using AntDesign.ForwardRef.Current. |
ForwardRef | -- |
| Method Signature | Return Type | Description |
|---|---|---|
| Reset() | void | Reset all the values in the form |
| Submit() | void | Submit the form. Will trigger validation and either AntDesign.Form`1.OnFinish or AntDesign.Form`1.OnFinishFailed. |
| Validate() | Boolean | Execute validation |
| ValidationReset() | void | Reset validation |
| SetValidationMessages(String field, String[] errorMessages) | void | Set validation messages to a specific field. |
FormValidateMode API#
Underlying Type: Int32
| Name | Description |
|---|---|
| Default | Validation will come from data attributes on the model provided to AntDesign.Form`1.Model |
| Rules | Validation will come from rules on FormItems in the form |
| Complex | Use both Default mode and Rules mode |
FormItem API#
| Property | Description | Type | Default Value |
|---|---|---|---|
| Name | ParameterSpecific the name of the form item. It also can used as the Member Path for binding the property of the Model. | String | -- |
| ChildContent | ParameterContent for the form item. Typically will contain one of the input elements | RenderFragment | -- |
| Label | ParameterCustom label for the item. If neither AntDesign.FormItem.Label or AntDesign.FormItem.LabelTemplate are provided, the DisplayName attribute value or field name will be used (in that order). |
String | -- |
| LabelTemplate | ParameterCustom label content for the item. Takes priority over AntDesign.FormItem.Label. If neither AntDesign.FormItem.Label or AntDesign.FormItem.LabelTemplate are provided, the DisplayName attribute value or field name will be used (in that order). |
RenderFragment | -- |
| LabelCol | ParameterControl the layout of the label. Commonly used to set widths for different screen sizes. | ColLayoutParam | -- |
| LabelAlign | ParameterAlign the label to the left or right | AntLabelAlignType? | -- |
| LabelColSpan | ParameterGets/sets the Span property on AntDesign.FormItem.LabelCol. |
OneOf<String, Int32> | -- |
| LabelColOffset | ParameterGets/sets the Offset property on AntDesign.FormItem.LabelCol. |
OneOf<String, Int32> | -- |
| WrapperCol | ParameterControl the layout of the input element's wrapper. Commonly used to set widths for different screen sizes. | ColLayoutParam | -- |
| WrapperColSpan | ParameterGets/sets the Span property on AntDesign.FormItem.WrapperCol. |
OneOf<String, Int32> | -- |
| WrapperColOffset | ParameterGets/sets the Offset property on AntDesign.FormItem.WrapperColOffset. |
OneOf<String, Int32> | -- |
| NoStyle | ParameterNo style when true, it is used as a pure field control | Boolean | -- |
| Required | ParameterMark this item as required for validation purposes | Boolean | -- |
| LabelStyle | ParameterStyle that will only be applied to label element. Will not be applied if LabelTemplate is set. | String | -- |
| Rules | ParameterValidation rules to apply to this item | FormValidationRule[] | -- |
| HasFeedback | ParameterUsed in conjunction with AntDesign.FormItem.ValidateStatus to display the verification status icon. It is recommended to use it only with the Input component |
Boolean | -- |
| ShowFeedbackOnError | ParameterWhether to show feedback icon on error. If set to false, it will not show the icon even if the field is in error state. | Boolean | -- |
| ValidateStatus | ParameterValidation status, if not set, it will be automatically generated according to validation rules | FormValidateStatus | -- |
| Help | ParameterPrompt information | String | -- |
| ToolTip | ParameterFormItem Help Tooltip information | String | -- |
| Id | ParameterID for the component's HTML | String | Uniquely Generated ID |
| Class | ParameterSpecifies one or more class names for an DOM element. | String | -- |
| Style | ParameterSpecifies an inline style for a DOM element. | String | -- |
| RefBack | ParameterA ForwardRef instance. You can get a reference to the internal DOM by using AntDesign.ForwardRef.Current. |
ForwardRef | -- |
FormValidationRule API#
| Property | Description | Type | Default Value |
|---|---|---|---|
| Len | Validate the length. Valid AntDesign.FormValidationRule.Types: String, Number, or Array. |
Decimal? | -- |
| Min | Validate length is greater than or equal to this number. Valid AntDesign.FormValidationRule.Types: String, Number or Array. |
Decimal? | -- |
| Max | Validate length is less than or equal to this number. Valid AntDesign.FormValidationRule.Types: String, Number, or Array. |
Decimal? | -- |
| Required | Make a field required | Boolean? | -- |
| Pattern | Validate the value passes a regular expression pattern | String | -- |
| Message | Custom error message. Will be auto generated if not provided. | String | -- |
| Range | Validate the value is in the specified range | ValueTuple<Double, Double?? | -- |
| DefaultField | Validate rule for all array elements. Valid AntDesign.FormValidationRule.Types: Array. (FormItem not supported now) |
FormValidationRule | -- |
| OneOf | Whether the value is in specified values | Object[] | -- |
| Enum | Validate the value is in specified enum type. | Type | -- |
| Fields | Validate rule for child elements. Valid AntDesign.FormValidationRule.Types: Array, Object |
Dictionary<Object, FormValidationRule> | -- |
| Validator | Custom validation function | Func<FormValidationContext, ValidationResult> | -- |
| Transform | Transformation function called before validation executes. The return value will have the validation ran against it. | Func<Object, Object> | -- |
| Type | Type of form field. See FormFieldType for all possible values. |
FormFieldType? | -- |
| ValidationAttribute | Validate the value using the specified attribute. | ValidationAttribute | -- |
FormValidateErrorMessages API#
| Property | Description | Type | Default Value |
|---|---|---|---|
| Default | Default generic validation error message | String | -- |
| Required | Default validation message for the Required rule | String | -- |
| Enum | Default validation message for the Enum rule | String | -- |
| Whitespace | Default validation message for the Whitespace rule | String | -- |
| Date | Messages for date type | DateMessage | -- |
| Types | Messages for when a field's type does not match the expected type | TypesMessage | -- |
| String | Messages for string type | CompareMessage | -- |
| Number | Messages for string type | CompareMessage | -- |
| Array | Messages for array type | CompareMessage | -- |
| Pattern | Messages for the Pattern validation rule | PatternMessage | -- |