Capture Backspace etc.

Hi,

snippet

    <div>
        <SfTextBox @ref="textboxObj"
                   CssClass="text-custom"
                   @onkeypress='@(e => KeyPressed(e))'
                   Created="onCreated"
                   @bind-Value="ValueString" />

    </div>

        public async void KeyPressed(KeyboardEventArgs args)
        {
            if (args.Key == "Enter")
            {
                await GetEmployeeData();
                ValueString = "";
            }
            else
            {
                ValueString += args.Key;
            }
            StateHasChanged();
        }

The KeyPressed doesn't capture the backspace key.
Is it possible?

Best regards,

Thijs van Rijswijk

3 Replies 1 reply marked as answer

JM Jeyanth Muthu Pratheeban Sankara Subramanian Syncfusion Team August 21, 2020 08:16 AM UTC

Hi Thijs,

Greetings from Syncfusion support.

We would like to know you that keypress event will only be triggered for valid character values like alphabetic, numeric and special characters and this is the behavior for native input also. So we suggest you to use KeyUp event for non printable characters.  Please refer to the below github answer for further reference. We have made sample for your convenience and kindly check the same.

GitHub Link        : https://github.com/dotnet/aspnetcore/issues/15581#issuecomment-429583505 

Regards, 
Jeyanth. 


Marked as answer

SO Sergi Ortiz Gómez May 1, 2023 06:42 AM UTC

To detect they keyb pressed always is much better use onkeyup and/or onkeybdown.


If you need to detect TAB must be in onkeydown, also when you need to detect combination of keys like SHIFT or CONTROL.



UD UdhayaKumar Duraisamy Syncfusion Team May 1, 2023 05:08 PM UTC

Thank you for your feedback and suggestion on the event to use for detecting key presses. We appreciate your insight on using onkeyup or onkeydown and the importance of using onkeydown for detecting the TAB key and key combinations like SHIFT or CONTROL.


Loader.
Up arrow icon