Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MudForm : Simplify form with FluentValidation #3793

Merged

Conversation

ghost
Copy link

@ghost ghost commented Jan 23, 2022

Description

This PR simplify the use of FluentValidation with MudForm.
Before we had to setup each field in a MudForm with a Validation property.
Ex:

<MudForm Model="@model" @ref="@form">
    <MudTextField @bind-Value="model.Name"
                  Validation="@(orderValidator.ValidateValue)"
                  For="@(() => model.Name)"
                  Immediate="true"
                  Label="Name" />

    <MudTextField @bind-Value="model.Email"
                  Validation="@(orderValidator.ValidateValue)"
                  For="@(() => model.Email)"
                  Immediate="true"
                  Label="Email" />

    <MudTextField @bind-Value="model.CCNumber"
                  Validation="@(orderValidator.ValidateValue)"
                  For="@(() => model.CCNumber)"
                  Immediate="true"
                  Label="Credit card nr" />

    <MudTextField @bind-Value="model.Address.Address"
                  Validation="@(orderValidator.ValidateValue)"
                  For="@(() => model.Address.Address)"
                  Immediate="true"
                  Label="Address" />
</MudForm>

Now we can set the Validation to the MudForm and every field will automatically get this value unless we prevent the override by setting OverrideFieldValidation to false.

Ex:

<MudForm Model="@model" @ref="@form" Validation="@(orderValidator.ValidateValue)">
    <MudTextField @bind-Value="model.Name"
                  For="@(() => model.Name)"
                  Immediate="true"
                  Label="Name" />

    <MudTextField @bind-Value="model.Email"
                  For="@(() => model.Email)"
                  Immediate="true"
                  Label="Email" />

    <MudTextField @bind-Value="model.CCNumber"
                  For="@(() => model.CCNumber)"
                  Immediate="true"
                  Label="Credit card nr" />

    <MudTextField @bind-Value="model.Address.Address"
                  For="@(() => model.Address.Address)"
                  Immediate="true"
                  Label="Address" />
</MudForm>

How Has This Been Tested?

  • Unit tests have been written.
  • Documentation have been updated and tested.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • The PR is submitted to the correct branch (dev).
  • My code follows the code style of this project.
  • I've added relevant tests.

@ghost
Copy link
Author

ghost commented Jan 23, 2022

This PR is waiting for #3788 to be merged.

@codecov
Copy link

codecov bot commented Jan 23, 2022

Codecov Report

Merging #3793 (bc16dba) into dev (2736ae7) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##              dev    #3793   +/-   ##
=======================================
  Coverage   91.02%   91.02%           
=======================================
  Files         350      350           
  Lines       11427    11434    +7     
=======================================
+ Hits        10401    10408    +7     
  Misses       1026     1026           
Impacted Files Coverage Δ
src/MudBlazor/Components/Form/MudForm.razor.cs 98.83% <100.00%> (+0.10%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2736ae7...bc16dba. Read the comment docs.

@ghost ghost marked this pull request as ready for review January 23, 2022 22:29
@JonBunator JonBunator added enhancement New feature or request needs review API change API that needs approval labels Jan 24, 2022
@ghost ghost force-pushed the feature/mudForm-simplify-fluent-validation branch from 1579b99 to 5ba8b74 Compare February 5, 2022 15:51
@henon
Copy link
Collaborator

henon commented Feb 5, 2022

Is this backwards compatible? If someone does it the old way their validation would still work as before?

@henon henon removed the needs review label Feb 5, 2022
@ghost
Copy link
Author

ghost commented Feb 5, 2022

Is this backwards compatible? If someone does it the old way their validation would still work as before?

@henon Yes it is backward compatible. Look at Using Simple Fluent Validation or Simple Form Validation in the docs. :)
For reference:

<MudForm>
    <MudTextField @bind-Value="creditCardNr" Validation="@ccValidator.Validation" Immediate="true" Label="Credit card nr" />
</MudForm>

@henon henon merged commit f7116cb into MudBlazor:dev Feb 6, 2022
@henon
Copy link
Collaborator

henon commented Feb 6, 2022

Great! Thanks.

@henon henon added this to the 6.0.7 milestone Feb 6, 2022
@ghost ghost deleted the feature/mudForm-simplify-fluent-validation branch February 25, 2022 04:34
jammerware pushed a commit to jammerware/MudBlazor that referenced this pull request Sep 20, 2022
* MudForm : Fix registering of form controls

* MudForm : Simplify form with FluentValidation

Co-authored-by: Meinrad Recheis <meinrad.recheis@gmail.com>
jammerware pushed a commit to jammerware/MudBlazor that referenced this pull request Sep 20, 2022
* MudForm : Fix registering of form controls

* MudForm : Simplify form with FluentValidation

Co-authored-by: Meinrad Recheis <meinrad.recheis@gmail.com>
jammerware pushed a commit to jammerware/MudBlazor that referenced this pull request Sep 20, 2022
* MudForm : Fix registering of form controls

* MudForm : Simplify form with FluentValidation

Co-authored-by: Meinrad Recheis <meinrad.recheis@gmail.com>
jammerware pushed a commit to jammerware/MudBlazor that referenced this pull request Sep 20, 2022
* MudForm : Fix registering of form controls

* MudForm : Simplify form with FluentValidation

Co-authored-by: Meinrad Recheis <meinrad.recheis@gmail.com>
3dots pushed a commit to 3dots/MudBlazor that referenced this pull request Mar 23, 2023
* MudForm : Fix registering of form controls

* MudForm : Simplify form with FluentValidation

Co-authored-by: Meinrad Recheis <meinrad.recheis@gmail.com>
ferraridavide pushed a commit to ferraridavide/MudBlazor that referenced this pull request May 30, 2023
* MudForm : Fix registering of form controls

* MudForm : Simplify form with FluentValidation

Co-authored-by: Meinrad Recheis <meinrad.recheis@gmail.com>
ilovepilav pushed a commit to ilovepilav/MudBlazor that referenced this pull request Nov 25, 2023
* MudForm : Fix registering of form controls

* MudForm : Simplify form with FluentValidation

Co-authored-by: Meinrad Recheis <meinrad.recheis@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API change API that needs approval enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants