Hi, I read Mike’s article and thought that this would be easy to accomplish, but it seems only to work when you can actually set a function in your html that passes the #input variable into the Component controller code as a parameter. I want to set the focus to a text area immediately after the user closes a modal (dismiss event handler), but I found two issues in this scenario.
Since this method isn’t called from the html, passing the parameter is not possible, so getting a reference to the actual TextArea is not possible. I tried using document.getElementById() which seems to get a reference to the actual ion-textarea element, but then…
There seems to be no access (through Typescript) to the setFocus() method in the TextArea type, the error reported in the Chrome Developer Tools is that this method is private from the InputBase class. Then I tried setting the actual variable returned by getElementById() into type “any” and set the focus() method manually but it didn’t work, no error at all but then it did nothing.
How can I do a setFocus() to a Ion-TextArea element from the Modal dismiss() handler? This is a) Getting the reference to the textbox (if possibly a typed reference) and b) what type it has to be in order to use the setFocus() method? How can I make this work?
I really don’t think a plunkr is necessary for this question as it is very straightforward, but if you want me to create one so you can help to solve this, please let me know and I will gladly invest the time to create one.
In our case, I realized that we needed another extra field to be used as “title” for the description on the textarea, so it was easy just to add an input before, then created the directive to activate the control and added just as a little extra, an attribute to the directive that would activate it when set to true, then on the onDidDismiss() event of the modal I changed the model variable that activates the directive and shows the device keyboard and voalá! it all worked, here is the code:
Adding this directive and setting the “activate” attribute to a model variable in your controller will allow you to activate the focusing and the keyboard without issues (at least it’s working for us as of beta 11).
Thanks for this topic. I was able to fix this issue by just adding an ion-input to the modal and make it’s display property none. This resulted in the textarea not focusing.