Cannot shift the focus from grid to textbox

Hi,

I have two text boxes and after entering data and by pressing add button it should add new data to the grid. And then the focus should come to the first text box again to ready to enter another set of data. But after adding data to the gird, the focus doesn't move to the first text box as expected. I have attached a sample project with this.

Thank you and best regards

Kalum


Attachment: WebApplication1_63574c9.zip

3 Replies 1 reply marked as answer

RR Rajapandi Ravi Syncfusion Team August 21, 2023 11:18 AM UTC

Hi kalum,


Greetings from Syncfusion support


After reviewing your query, we found that you are invoke the focus() in the keypress before the record is added to the Grid. It was the cause of the problem. We need to invoke the focus() after the record is added to the Grid, then only the focus is maintained in the Textbox. Please refer the below code example and sample for more information.


Index.cshtml

 

function setFocus(fromObj, toObj) {

        document.getElementById(fromObj).addEventListener('keypress', async (args) => {

 

            if (args.key == 'Enter') {

                setTimeout((e) => {

                    document.getElementById(toObj).focus();

                }, 300)

 

            }

        })

 

    }

 


Sample:


Regards,

Rajapandi R


Attachment: 184159_da65e00f.zip

Marked as answer

KA kalum August 22, 2023 03:51 PM UTC

Hi Ravi,

This works fine and thanking you very much for your prompt support.


Kalum



SG Suganya Gopinath Syncfusion Team August 23, 2023 06:52 AM UTC

Hi Kalum, 

We are glad that the provided solution helped to solve the issue. Please get back to us for further assistance when needed. 

We are marking this ticket as solved. 


Loader.
Up arrow icon