2
I am developing an application in Blazor and managed to do an inputtext along with a button perform a search in an api created by scafolding with Entity Frameworks.
Follow simple form below.
<label>Hello @motorista !!</label>
<input type="text" @bind-value="motorista" />
<button class="btn btn-primary" @onclick="PesquisaMotorista">Click me</button>
@code {
private string motorista = null;
Veiculo[] veiculos { get; set; }
protected async Task PesquisaMotorista()
{
veiculos = await http.GetJsonAsync<Veiculo[]>($"api/veiculos/motorista/{motorista}");
}
}
I would like to use the onchange event in the input, to no longer need the button of the form above.
Below follows the same form without the button and with the oninput event that is not working as the onchange event.
How to use in the example below the onchange event?
<label>Hello @motorista !!</label>
<input type="text" @bind-value="motorista" @oninput="PesquisaMotorista" />
@code {
private string motorista = null;
Veiculo[] veiculos { get; set; }
protected async Task PesquisaMotorista()
{
veiculos = await http.GetJsonAsync<Veiculo[]>($"api/veiculos/motorista/{motorista}");
}
}
Some tests carried out so far
With onclick type the text and give a click on the input ai the search is performed
<input type="text" @bind-value="motorista" @bind-value:event="oninput" @onclick="PesquisaMotorista" />
With onchange type the text and give a enter, then the search is performed
<input type="text" @bind-value="motorista" @bind-value:event="oninput" @onchange="PesquisaMotorista" />
Solution obtained with the onkeyup event
<input type="text" @bind-value="motorista" @bind-value:event="oninput" @onkeyup="PesquisaMotorista" />
Are you using any js framework? jquery type?
– Renan
I’m not using any kind of js and jquery frameworks - I’m looking to use the concepts of Blazor, have to use something ?
– Cyberlacs
<input type="text" @bind-value="driver" @bind-value:Event="oninput" @onchange="Search driver" /> - in this example the onchange event is working but strange mode, we have to type a text first and enter, then performs the search
– Cyberlacs
Solution obtained with the onkeyup event, see example in the update of the question post
– Cyberlacs
puts your solution in a response, and marks your own response as the solution.
– Renan