I want to set focus on a form element. With jQuery it's that simple, just $('selector').focus
.
I created a simple <input ref="xxx" id="xxx" type="text">
and in my .ts file I add a property and use it here:
attached() { this.xxx.focus() }
Nothing happens. At first I feel that some easy things are becoming difficult, and I am sure that there never was a point.
(The original use case was to set focus on a form element inside Bootstrap camber when crash is shown, for example:
// set focus to the first element when the add-cell collapse is shown $('#collapsedAddTask').on('shown.bs.collapse', function () { $('#AddTaskTitle').focus() })
This works for my main HTML (not a single page application), but not with Aurelia. What is Aurelia?
Update Using the answer from Miroslav Popovich below, and in the comments, I made it work like this (remember that this is a component of the Bootstrap partition):
<div class="panel-heading"> <a href="#collapsedAddTask" data-toggle="collapse" id="addTaskHeader" click.delegate="addTaskShown()">Add task</a> </div> <div class="panel-body"> <div class="collapse" id="collapsedAddCell"> <input type="text" focus.bind="addTaskFocused"> </div> </div>
source share