I'm afraid I'm hitting a limit of Lightning here, but I'd thought I ask here as a last resort.
I want to programmatically add focus on a field in a form.
I now have code like this;
Markup:
<ui:inputText label="Duration" aura:id="DurationHhMm__c" blur="{!c.onDurationFieldChange}" updateOn="keyup"/>
Javascript:
component.find('DurationHhMm__c).getElement().focus();
But, this is not working. When I console.log(component.find('DurationHhMm__c').getElement())
, I know why. Instead of the actual input, I get this back:
I am assuming there is no way I can call a Lightning method to focus the input and a more granular find is not allowed because of LockerService?
I realise I can just not use the Lightning component, and just do a plain input field, but I need to add focus dynamically and rather not change around the entire app at this point. And would this even work?
component.find("DurationHhMm__c").getElement().getElementsByTagName("INPUT")[0].focus()
? Locker Service is only meant to lock you out of the entire DOM, but not the DOM within your component. – sfdcfox Nov 21 '16 at 17:50