function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Deja BondDeja Bond 

Lightning Dropdown selection

Hi, so I have thid lightning dropdown menu, and upon selection of a menu item, I would like to display a modal. I have the code for the menu and the modal, I just do not understand how to connect the two, i.e display the modal when I am selecting an item.User-added image
And this is my modal code
User-added image
So the goal is that when the Add Candidate menu item is selected, the modal appears... any help would be greatly appreciated.
Best Answer chosen by Deja Bond
Maharajan CMaharajan C
HI Deja,

  If your are using only the single component which holds the modal and lightning:buttonMenu then you cansimply use the Boolean attribute to handle this like below:

    
    <aura:component>
    
    <aura:attribute name="openModal" type="boolean" default="false"/>

    <lightning:buttonMenu aura:id="menu" onselect="{! c.handleSelect }" alternativeText="Show menu">
        <lightning:menuItem value="MenuItemOne" label="Menu Item One" />
        <lightning:menuItem value="MenuItemTwo" label="Menu Item Two" />
        <lightning:menuItem value="MenuItemThree" label="Menu Item Three" />
        <lightning:menuItem value="MenuItemFour" label="Menu Item Four" />
    </lightning:buttonMenu>
    
    <aura:if isTrue="{!v.openModal}">
    
        ///////   Add your Modal code here ///////////////
    
    </aura:if>
    
  </aura:component>
  
  ({
    handleSelect: function (cmp, event, helper) {
        var selectedMenuItemValue = event.getParam("value");
        if(selectedMenuItemValue == 'Add Candidate')
        {
            component.set("v.openModal", true);
        }
    }
 })


Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!


Thanks,
Maharajan.C
 

All Answers

Maharajan CMaharajan C
HI Deja,

  If your are using only the single component which holds the modal and lightning:buttonMenu then you cansimply use the Boolean attribute to handle this like below:

    
    <aura:component>
    
    <aura:attribute name="openModal" type="boolean" default="false"/>

    <lightning:buttonMenu aura:id="menu" onselect="{! c.handleSelect }" alternativeText="Show menu">
        <lightning:menuItem value="MenuItemOne" label="Menu Item One" />
        <lightning:menuItem value="MenuItemTwo" label="Menu Item Two" />
        <lightning:menuItem value="MenuItemThree" label="Menu Item Three" />
        <lightning:menuItem value="MenuItemFour" label="Menu Item Four" />
    </lightning:buttonMenu>
    
    <aura:if isTrue="{!v.openModal}">
    
        ///////   Add your Modal code here ///////////////
    
    </aura:if>
    
  </aura:component>
  
  ({
    handleSelect: function (cmp, event, helper) {
        var selectedMenuItemValue = event.getParam("value");
        if(selectedMenuItemValue == 'Add Candidate')
        {
            component.set("v.openModal", true);
        }
    }
 })


Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!


Thanks,
Maharajan.C
 
This was selected as the best answer
Deja BondDeja Bond
Thanks! I will try now!
Deja BondDeja Bond
I keep getting this error
User-added image
for the line
    <aura:attribute name="openModal" type="boolean" default="false"/>
 
Deja BondDeja Bond
Got it. that line was in the wrong place