locked
How to get the changed value in InputText RRS feed

  • Question

  • User2076108182 posted

    Hi:

    I have a balzor client project

    I want to get value when I change the input text,like 

    <InputText id="num" @bind-Value="@para.Num.ToString()" @bind:event="oninput" />

    How to write the oninput function?

    Thanks for your help

    Friday, October 11, 2019 3:13 AM

All replies

  • User1052024640 posted

    Hello, 潘凤:

    I do it like this:

    @code{
    
    private class MsgModel{
    
    public string Msg{get;set;}
    
    }
    
    private MsgModel _InputMsgModel { get; set; } = new MsgModel();
    
    private void SubmitText()
    {
    if (!string.IsNullOrEmpty(_InputMsgModel.Msg))
    {
    ///code something...
    }
    }
    
    }
    
    <EditForm Model="_InputMsgModel" OnValidSubmit="@SubmitText" id="inputText">
    <InputText @bind-Value="_InputMsgModel.Msg" type="text"  />
    </EditForm>

    Wednesday, October 16, 2019 3:08 AM
  • User2076108182 posted

    Hello, 潘凤:

    I do it like this:

    @code{
    
    private class MsgModel{
    
    public string Msg{get;set;}
    
    }
    
    private MsgModel _InputMsgModel { get; set; } = new MsgModel();
    
    private void SubmitText()
    {
    if (!string.IsNullOrEmpty(_InputMsgModel.Msg))
    {
    ///code something...
    }
    }
    
    }
    
    <EditForm Model="_InputMsgModel" OnValidSubmit="@SubmitText" id="inputText">
    <InputText @bind-Value="_InputMsgModel.Msg" type="text"  />
    </EditForm>

    thanks for your reply. nut I mean I want to trigger the client event when textbox change , someing like autocomplete

    Thursday, October 17, 2019 12:55 AM
  • User1052024640 posted

    There is also a @onchange property in the EditForm. I think you can use it.

    Thursday, October 17, 2019 1:58 AM
  • User1021841275 posted

    If you mean to use the textbox as an AutoComplete, that's not what I'll answer here.

    If you want to get value in the text box you can use:

    <InputText @bind-Value="StrMsg" @oninput="@(() => YourFunctionName(valueIfYouNeedIt))" type="text" />

    or any other @on-event that suits you.

    Monday, December 2, 2019 4:25 PM