I am trying to trigger the model validation in Blazor by using EditForm
.
For some reason, the oninput
event doesn't seem to be called if using the InputText
, but it works using a simple input
element.
Have I missed something?
Here is an HTML sample:
<EditForm Model="@Model" OnValidSubmit="@OnValidSubmit" id="authorize">
<h1 class="mb-3">
<span class="d-block">Authorize</span>
</h1>
<DataAnnotationsValidator />
<div class="form-group">
<label class="sr-only" for="AuthorizeUsername">Username</label>
<div class="input-group mb-2">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fas fa-user"></i></div>
</div>
<InputText type="text" class="form-control" id="AuthorizeUsername" placeholder="Username" @bind-value="@Model.Username" @bind-value:event="oninput" />
</div>
</div>
<div class="form-group">
<label class="sr-only" for="AuthorizePassword">Password</label>
<div class="input-group mb-2">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fas fa-asterisk"></i></div>
</div>
<InputText type="password" class="form-control" id="AuthorizePassword" placeholder="Password" @bind-value="@Model.Password" @bind-value:event="oninput" />
</div>
</div>
<div class="form-group">
<ValidationSummary />
<button type="submit" class="btn btn-outline-primary"><i class="fas fa-sign-in-alt mr-1"></i> Login</button>
</div>
</EditForm>
bind-value:event
format you're using. Try usingbind-value-oninput="@Model.Password"
– KnightlyInputText
. So yes it may be worth creating an issue for it – Knightlyinput
element instead of theInputText
element worked for me. – Dodi@bind-Value
becauseValue
is the name of a property on the C# classInputText
– Greatnephew