1

With the new migraine inducing locker service active, the getElement() function doesnt work, which in turn means you cant access child nodes within a lightning ui element.

In a situation where say an iterator is used to generate some picklist input fields, there is now no way to know which picklist field actually triggered an event, as you cannot dynamically attribute an id nor append data attributes.

Or is there ? Any ideas out there ?...

1

First and foremost not able to access child nodes with locker is a myth and not sure what made you think through those lines .

Lets say you have DOM element like below

<div aura:id="divId" id="myChart">
  <div class="new">
   <ul>
    <li> ..</li>
  </ul>
  </div>
</div>

You can trace through the DOM easily via below JS in your controller

init : function(component, event, helper) {
  var element = component.find("divId").getElement();
}
2
  • Apologies my question may not be clear enough, and thank you for your prompt and considered input. I have been trying to iterate over the children of, in your example, divId. I have found locker being active will prevent me traversing the DOM, which is documented elsewhere by Doug C of Salesforce as well. So present solution was not locker friendly. I have now achieved a locker compatible alternative for my use case which is outside scope of this question. Aug 12 '16 at 2:13
  • No problems .If you have create your DOM then you can access all the nodes of it . Aug 12 '16 at 2:15
2

I suspect you mean you can no longer do what we clearly said never to in the first place - reach into the internal details (not part of its API and therefore unsupportable by definition) of a component you fo not own. Are you trying to call getElement() on a component in the ui: namespace perhaps? The DOM internals of ui: namespace components were never something you could depend on and was guaranteed to break at a time when you least expect it. A big part of LS's job is to enforce long standing, but previously unenforceable, encapsulation guarantees.

If you want to track additional info like you describe in a Lightning Compoment way you'll need to stick to the public API for the components you are using if you do not own them. One approach would be to create your own component that composites and instance of the pick list and has a new attribute to track the additional data you want. Another approach could be to leverage the unique component.getGlobalId() that all components have and is exposed in even when LS is activated.

3
  • Thanks Doug for your input also. I guess it is an ongoing learning curve on a relatively new technology , and my revised solution is an improvement over previous hack so is good outcome 👍 Aug 12 '16 at 2:33
  • 2
    Cool - and yes LS is migraine inducing for those of us both building and using it (I just ran into an API showstopper tonight with one of my own open source projects, aura-ng, because in my case I was using undocumented/unsupported private Aura a Framework APIs, d'oh since I am on the Aura team!). Would you mind posting your final, working solution for others (including me) to learn from? Aug 12 '16 at 2:39
  • Hi Doug - I didnt get a chance to prepare a stripped back sample sorry. I recall I didnt use either of the suggested approaches so probably best not to publish my work here anyway! Dec 1 '16 at 21:17
0

I think it is important to highlight that the components in lightning namespace are in beta. A lot of functionality that needs to come with them is not available.

All ui events in lightning namespace return DOM Events and not aura events as the other components. The information in the DOM events is hidden by the locker service so there is no way around it.

Another problem you might find is the validityState. Because you don't have access to DOM elements you are given a convenient way to access the validityState to validate user input. However, there is no way to execute checkValidation or setCustomValidity functions because again all DOM events are hidden and the methods are not provided by the current implementation of the components.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.