Skip to content

Commit

Permalink
Fixed register password validation
Browse files Browse the repository at this point in the history
- Trigger a validation on the "Repeat Password" field when the "Password" field value has changed
  • Loading branch information
TheSpartaPT committed Oct 23, 2024
1 parent fe85758 commit 2452c0f
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions Fuyu.Launcher/Pages/Register.razor
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
<MudPaper Class="pa-4" Elevation="4">
<MudForm @ref="_form" @bind-IsValid="@_success" @bind-Errors="@_errors">
<MudTextField @bind-Value="_username" Label="Username" Required="true" RequiredError="Required" />
<MudTextField @bind-Value="_password" Label="Password" Required="true" RequiredError="Required"
InputType="InputType.Password"
HelperText="Choose a strong password" />
<MudTextField T="string" Label="Repeat the Password" Required="true" InputType="InputType.Password" Validation="@(new Func<string, string>(PasswordMatch))" />
<MudTextField @bind-Value="_password" @bind-Value:after="Password_Changed" Label="Password" Required="true" RequiredError="Required"
InputType="InputType.Password"
HelperText="Choose a strong password" />
<MudTextField @ref="_repeatPwField" T="string" Label="Repeat the Password" Required="true"
InputType="InputType.Password"
Validation="@(new Func<string, string>(PasswordMatch))" />
<div class="d-flex align-center justify-center mt-6">
<MudButton Variant="Variant.Filled" Color="Color.Tertiary" Disabled="@(!_success)" OnClick="Register_Clicked">Register</MudButton>
</div>
Expand All @@ -43,11 +45,18 @@
private string _username = string.Empty;
private string _password = string.Empty;

private MudTextField<string> _repeatPwField;

private string PasswordMatch(string arg)
{
return _password != arg ? "Passwords don't match" : null;
}

public void Password_Changed()
{
_repeatPwField.Validate();
}

public void Register_Clicked()
{
_form.Validate();
Expand Down

0 comments on commit 2452c0f

Please sign in to comment.