This is just the weirdest thing. I've got a Sammy.js app, and I want to set focus on a text field right after the HTML loads. I've got this CoffeeScript here:
this.partial('templates/my-template.jqt').then ->
i = $('#item')
debugger
i.focus()
While I'm in the debugger, right on that line, I can inspect "i" and see that it's a JQuery object. I can even call i.val("HI THERE!") and see my text field update. But, calling i.focus() does absolutely nothing. Is there some security feature I'm missing that doesn't let you focus on a text element that was dynamically loaded?
You can use the SetFocus method when you want a particular field or control to have the focus so that all user input is directed to this object. To read some of the properties of a control, you need to ensure that the control has the focus. For example, a text box must have the focus before you can read its Text property.
Now that you have a FocusNode , pass it to a specific TextField in the build () method. 3. Give focus to the TextField when a button is tapped Finally, focus the text field when the user taps a floating action button. Use the requestFocus () method to perform this task.
expression A variable that represents a TextBox object. You can use the SetFocus method when you want a particular field or control to have the focus so that all user input is directed to this object. To read some of the properties of a control, you need to ensure that the control has the focus.
Pass the FocusNode to a TextField Now that you have a FocusNode , pass it to a specific TextField in the build () method. 3. Give focus to the TextField when a button is tapped Finally, focus the text field when the user taps a floating action button.
Try:
setTimeout(function() { $('#item').focus() }, 1);
It's quite common issue. For some reason delaying the focus for 1ms makes it working.
JQuery's focus() doesn't focus on an element, it binds an event handler to focus. http://api.jquery.com/focus/
Try i.get().focus() instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With