Blazor PasswordInput
The Blazor Bootstrap PasswordInput component is constructed using an HTML input of type 'password'.
Basic usage #
Disable #
Use the
Disabled
parameter to disable the PasswordInput
.Entered password:
<div class="mb-3">
<PasswordInput @bind-Value="@enteredPassword" Disabled="@disabled" />
</div>
<div class="mb-3">Entered password: @enteredPassword</div>
<Button Color="ButtonColor.Primary" @onclick="Enable"> Enable </Button>
<Button Color="ButtonColor.Secondary" @onclick="Disable"> Disable </Button>
<Button Color="ButtonColor.Warning" @onclick="Toggle"> Toggle </Button>
@code {
private string? enteredPassword = null;
private bool disabled = true;
private void Enable() => disabled = false;
private void Disable() => disabled = true;
private void Toggle() => disabled = !disabled;
}
Also, use Enable() and Disable() methods to enable and disable the
PasswordInput
.NOTE
Do not use both the Disabled parameter and Enable() & Disable() methods.
Entered text:
<div class="mb-3">
<PasswordInput @ref="passwordInputRef" @bind-Value="@enteredPassword" />
</div>
<div class="mb-3">Entered text: @enteredPassword</div>
<Button Color="ButtonColor.Secondary" @onclick="Disable"> Disable </Button>
<Button Color="ButtonColor.Primary" @onclick="Enable"> Enable </Button>
@code {
private PasswordInput? passwordInputRef;
private string? enteredPassword = null;
private void Disable() => passwordInputRef.Disable();
private void Enable() => passwordInputRef.Enable();
}
Valdations #
Like any other blazor input component,
PasswordInput
supports validations.
Add the DataAnnotations on the PasswordInput
component to validate the user input before submitting the form.
In the below example, we used Required attribute.
Events: ValueChanged #
This event fires when the
PasswordInput
value changes, but not on every keystroke.