logo Enterprise-level component library based on Bootstrap and Blazor
gitee
oscs
version
license
download
repo
commit
build
coverage

ValidateForm

Form components that can be used for data compliance checks

Data compliance checks are automatically performed when components placed in the ValidateForm are submitted

Demo

Introduction

  • ValidateForm component supports asynchronous setting of Model values
  • The form event is for OnValidSubmit OnInvalidSubmit
  • Model parameter is required is not allowed to be empty
  • Multiple buttons can be placed within the form to set whether the ButtonType='ButtonType.Submit' parameter is submitted to the form
  • The client authentication mechanism supports the model's Required label, setting the default English prompt information when not set by setting the ErrorMessage parameter prompt
  • The form checks by default whether the binding field values within the form are legitimate, and you can set the ValidateAllProperties property value to true if you need to check all fields in the model
  • Set the asynchronous submission form by setting the value of the Button Button property IsAsync
  • After the value of the component control in the form is modified, the OnFieldChanged method is called

Note:

  • Components within a form are typically used to bind the property values of Model in both directions using bidirectional binding techniques, causing the component to refresh and re-render when its value changes StateHasChanged, and the method is called, i.e. its component or page is refreshed and re-rendered
  • The default width of component front label is 120px. If you need more, please change the style variable --bb-row-label-width in the project style file or remove RowType.Inline

In this example, set the ShowLabelTooltip in the form-inline style to true to make the mouse hover over the cropped label to display the complete information

Place the support form components into the ValidateForm

Demo

Examples of components that support form validation

Example illustration

  • The name is the string type
  • The age is an integer type
  • Birthday is the datetime type
  • Education is an enumeration type
  • Hobbies are collection types

In this example, by setting the submit button property IsAsync to submit the form asynchronously, click Submit to disable itself, and resume after the asynchronous operation is complete

Name
Test
  •  
  • 0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 18
  • 20
  • 21
  • 22
  • 23
  •  
  • 0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 37
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  •  
  • 0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 15
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
2023 March
SunMonTueWedThuFriSat
26
27
28
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec

Set the custom error message by calling SetError method

Demo

Scenario

the client verification after the pass of the database save operation, if other problems, you can still make a form custom error prompt, in this case, after the data verification is legal, click the submit form button, the name field will show, the database already exists such a custom prompt

  •  
  • 0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 18
  • 20
  • 21
  • 22
  • 23
  •  
  • 0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 37
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  •  
  • 0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 15
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
2023 March
SunMonTueWedThuFriSat
26
27
28
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec

This component checks the model binding field values within the form by default, setting the ValidateAllProperties values if you need to check all field values for the model

Demo

The Address is not placed in this example, because the ValidateAllProperties parameter value is true, the Addres field is still checked, and OnInvalidSubmit is triggered when the data is submitted after all the data in the timely form is legitimate callback delegate

  •  
  • 0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 18
  • 20
  • 21
  • 22
  • 23
  •  
  • 0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 37
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  •  
  • 0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 15
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
2023 March
SunMonTueWedThuFriSat
26
27
28
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec

Supports any complex type of binding and validation

Demo

The second binding in this example is a super-complex type ComplexModel.Dummy.Dummy2.Name Empty the value, click submit the formvalidate the data. After the second text box verifies compliance, the error prompt is displayed again by calling the SetError

ComplexForm.SetError('Dummy.Dummy2.Name','数据库中已存在');

By changing the components within the form, verify that the form can still be validated correctly

Demo

Click the Change componentbutton address The component changes to count components, reset componentbutton recovery, name address component is required, count The component has a default value of 0 So you can check through the data

Set the alignment of labels throughout the station or in a specific form with style uniformity

Demo

Address text box adds email addressvalidation rules

<EditorItem @bind-Field="@context.Address" ValidateRules="@CustomerRules" />
Loading...

Add custom validation rules by setting Rules

Demo

Address text box adds email addressverification rules, click On Submission to verify

protected override void OnInitialized()
{
    base.OnInitialized();
    // Add mailbox validation rules
    CustomerRules.Add(new CustomerValidator(new EmailAddressAttribute()));

    // Used in Razor files
    // <BootstrapInput @bind-Value="@Model.Address" ValidateRules="@CustomerRules" />
}

call the ValidateForm instance method Validate for trigger the form validation

Demo

The button is not submit button. so not trigger the form submit action, in this sample code use OnClickWithoutRender parameter for improve performance.

[NotNull]
private ValidateForm? ValidatorForm { get; set; }

private Task OnClickValidate()
{
    ValidatorForm.Validate();
    return Task.CompletedTask;
}

When the focus is in the input box in the form, pressing Enter will automatically submit the form by default. You can disable automatic submission by setting DisableAutoSubmitFormByEnter="false"

Demo

form form is an important element ofweb. If there is an input element in the form, when this element gets the focus, pressing Enter will automatically submit the form. This is a feature of the form element, not our component code logic. If this function is not needed, disable it by setting DisableAutoSubmitFormByEnter="true", In this example, pressing Enter in the text box will not automatically submit and perform data compliance check. You need to click the Submit button to submit the form

Attributes

Loading...

Methods

Loading...

B station related video link

交流群

QQ Group:BootstrapAdmin & Blazor 795206915 675147445 Welcome to join the group discussion
img
Themes
Bootstrap
Motronic
Ant Design (完善中)
DevUI (制作中)
LayUI (完善中)
An error has occurred. This application may no longer respond until reloaded. Reload
Seems like the connection with the server has been lost. It can be due to poor or broken network. Please hang on while we're trying to reconnect...
Oh snap! Failed to reconnect with the server. This is typically caused by a longer network outage, or if the server has been taken down. You can try to reconnect, but if that does not work, you need to reload the page.
Oh man! The server rejected the attempt to reconnect. The only option now is to reload the page, but be prepared that it won't work, since this is typically caused by a failure on the server.
Bootstrap Blazor Component library updated to 7.4.4-beta01

Bootstrap Blazor at present has more than 120 components. This component is based on Bootstrap Blazor An enterprise-level component library that provides several types of common components such as layout, navigation, form, data, notification, icon, voice, etc. Each component has been carefully designed with modularity, responsiveness and excellent performance. Starting from more practical scenarios, meeting the needs of various scenarios, greatly reducing the time cost of developers, greatly shortening the development cycle, greatly improving development efficiency, and providing a set of General Rights Management System Example project。Bootstrap Blazor Products are maintained by a professional full-time technical team, with efficient response speed, diversified solutions, long-term support, and enterprise-level support. At present, it has been used in many well-known state-owned enterprises, and the project is running stably with a maximum of 1200 people online. On the right is the QR code of the Chinese Blazor QQ community with the largest number of people in China, welcome to scan and join the group.

component updated to 6.6.0 Change log [portal] If the component brings you convenience, please help to light up the project Star github gitee

QQGroup
QQ 795206915