Textbox: raise an event when clear button is clicked

Hello,

It would be great if you could raise an event when the clear text button is clicked on the textbox.

So far, I subscribe to the ValueChanged event and check if the string is null or empty, but this is not exactly the same as "ClearButtonClicked".

Thank you in advance.


5 Replies

BC Berly Christopher Syncfusion Team August 6, 2021 01:39 PM UTC

Hi Berger, 
  
By default, there is no event will be provided for fired when clicking the clear button. While clicking the clear button in the textbox component, the ValueChange event will be fired. We can confirm that whether the change event will be triggered by a keyboard action or by clicking the clear button in the ValueChange event arguments. Since, if you are clicking the clear icon, then you can get the event type as “mousedown” in the change event argument.  
  
<SfTextBox ShowClearButton="true" ValueChange="OnValueChange"></SfTextBox> 
 
@code{ 
    public void OnValueChange(ChangedEventArgs args) 
    { 
    } 
} 
 
  
On clicking clear icon: 
  
 
  
Regards, 
Berly B.C 



BS Berger Stephane August 7, 2021 05:35 PM UTC

Makes sense. 


Thanks a lot ffor your suggestion!



BC Berly Christopher Syncfusion Team August 9, 2021 05:10 AM UTC

Hi Berger, 
  
Most welcome. Please let us know if you need further assistance on this. 
  
Regards, 
Berly B.C 



EL Endre Lovas September 25, 2024 05:06 PM UTC

Hello,

What about SfNumericTextbox?



YS Yohapuja Selvakumaran Syncfusion Team September 26, 2024 01:16 PM UTC

Hi Endre Lovas,


Thank you for getting back to us. We have reviewed your requirement and confirmed that it is possible to achieve this with the NumericTextBox component. By default, there is no specific event triggered when clicking the clear button in the NumericTextBox. However, the ValueChange event will be fired when the clear button is clicked.


Please see the code snippet below for implementation:


 

 

<SfNumericTextBox TValue="int?" ShowClearButton="true">

    <NumericTextBoxEvents TValue="int?" ValueChange="@ValueChangeHandler"></NumericTextBoxEvents>

</SfNumericTextBox>

 

@code {

    private void ValueChangeHandler(Syncfusion.Blazor.Inputs.ChangeEventArgs<int?> args)

    {

        Console.WriteLine("Event triggered");

    }

}

 


Sample: https://blazorplayground.syncfusion.com/LZVTZEVRTcGJlWSD


You can refer to the below documentation for further reference,


Documentation: https://blazor.syncfusion.com/documentation/numeric-textbox/events#created



Regards,

Yohapuja S


Loader.
Up arrow icon