0

I'm creating a List that has one or more buttonIcons in the end.I'm creating these buttons dynamically with $A.createComponent. While clicking the button,I need to find which button is clicked and then finding its position with getBoundingClientRect(). How can I do it? I tried event.getSource(),event.currentTarget & event.target. Nothing helped! Or Is there any ways to find the position of a element in lightning. (I need to show a popup relative to the button's position,can't use lightning:helptext)

3

2 Answers 2

1
  1. First find the body of the parent component of the dynamically created components.
  2. Then find the button and getBoundingClientRect Refer this QA,

`

findButton : function(cmp) {
        var parentElement = cmp.find("parent").get("v.body");
        console.log("child 1",parentElement[buttonIndex].find("buttonId").getBoundingClientRect());
    }

`

0
0

Please Check the below code, It will help you to find which button you clicked.Can you please add your code snippets.

 <aura:component>
<aura:attribute name="whichButton" type="String" />

<p>You clicked: {!v.whichButton}</p>
  <ui:button aura:id="button1" label="Click me" press="{!c.nameThatButton}"/>
   <ui:button aura:id="button2" label="Click me too" press="
        {!c.nameThatButton}"/>
     </aura:component>

Javascript:

 ({
     nameThatButton : function(cmp, event, helper) {
    var whichOne = event.getSource().getLocalId();
    console.log(whichOne);
    cmp.set("v.whichButton", whichOne); } })
3
  • Thanks for the answer! But I'm dynamically creating the buttons with same aura:id.So can't do it with LocalId.
    – A.Bretto
    Nov 28, 2017 at 5:51
  • Okay. Can you please add your code snippets.
    – Annappa
    Nov 28, 2017 at 8:52
  • I did it with dynamically creating a new component instead of dynamically creating a button.Thanks
    – A.Bretto
    Nov 28, 2017 at 12:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .