Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force a focus on a component before the Form is shown

I have to show (with ShowModal) a Form with many TEdit but I want to force the focus on a TEdit, but not always the same, depending on the context.

I can't use SetFocus before the ShowModal (because the Form is not activate) and use the component Name or Tag is not convenient in my application. Do you have an idea ?

like image 417
philnext Avatar asked Mar 15 '13 08:03

philnext


People also ask

How do I set the focus to the first form field?

To set focus to an HTML form element, the focus() method of JavaScript can be used. To do so, call this method on an object of the element that is to be focused, as shown in the example. Example 1: The focus() method is set to the input tag when user clicks on Focus button.

How do you focus on a component in React?

To focus input when another element is clicked in React:Set the onClick prop on the other element. When the other element is clicked, focus the input, e.g. ref. current. focus() .

How will you focus on the input field when the page is loaded React?

Use the componentDidMount() Method in React Applying the componentDidMount() method enables the input field to focus after displaying the page. This function is good for making pages load faster as the function doesn't load data until after the first-page rendering and is called once.


1 Answers

The simplest way to achieve your goal, in my view, is to assign to the ActiveControl property for the form. You can do this before showing the form. When you form is later shown, the VCL framework will ensure that the ActiveControl is given input focus.

From the documentation:

If the form does not have focus, ActiveControl is the control on the form that will receive focus when the form receives focus.

like image 101
David Heffernan Avatar answered Sep 23 '22 00:09

David Heffernan