I have an input field:
<ui:inputText aura:id="name-input"/>
With controller code:
var input = cmp.find("name-input");
console.log(input);
input.focus();
This gives the error:
Access Check Failed! Component.method():'markup://ui:focus' is not visible to 'markup://c:TimeTagCreator {100:0}'.
I can even see that the .focus()
method exists, with the output of that console.log();
being:
What is going on here?
getElement()
isn't defined on lightning components when LockerService is enabled. That would would on an<input>
, but doesn't on a<ui:inputText>
getElement()
is defined on lightning components with LockerService enabled for components that you own. So if you built a <c:foo> component, for example, that had a single<input>
element inside,getElement()
would in fact return that input. It doesn't work in the OP case because the<input>
lives insideui:inputText
, which would only be accessible toui
components, not your custom namespace.focus()
is anaura:method
defined on theui:inputText
so if you are expectedfocus()
to be visible in the situation I describe with the custom built <c:foo> component, you need to explicitly define that aura:method yourself. I was just using the custom component as an example for howgetElement()
works.