0

I have the following component, right now when I change the inputSelect selectedValue is changing correct and I can see it changing in the console.log

<aura:component>
<aura:attribute name="options" type="List"/>
<aura:attribute name="pickListTitle" type="String"/>
<aura:attribute name="selectedValue" type="String"/>
<aura:attribute name="style_class" type="String" description="Style class 
 for div"/>

<aura:handler name="init" value="{!this}" action="{!c.init}"/>
<!-- "{!v.style_class}" -->
<div>
    <ui:inputSelect label="{!v.pickListTitle}" class="dynamic" aura:id="optionItems" change="{!c.onChange}" value="{!v.selectedValue}"/>
</div>

My goal is that I want to be able to see it in my top level component, I want to make one generic pick list that can handle any List of strings because I don't want to build this each any every time, how would I go about getting this value in my parent component?

<aura:component access="global" implements="flexipage:availableForAllPageTypes">
    <c:Tabs type="scoped">
         <c:Tab title="Item One">
            Test
            <c:Picklist pickListTitle="Picklist title" options="['Test 1','Test 2','Test 3']" pxWidth="15"/>
            <!-- Is it possible to return the value up? -->
        </c:Tab>
        <c:Tab title="Item One">
            Hello 1
        </c:Tab>
        <c:Tab title="Item Three">
            Hello 2
        </c:Tab>  
        <c:Tab title="Item Four">
        </c:Tab> 
    </c:Tabs>
</aura:component>
4
  • 1
    You can fire a custom event when your inputSelect value is changed and handle it in your parent component. As you can see here. Aug 28, 2017 at 16:02
  • 1
    You can also pass in an attribute from the parent to the child and use that in the value of the select. then when changed in the child it is automatically propogated
    – Eric
    Aug 28, 2017 at 16:08
  • @Eric I ended up doing what you said, I didn't see a reason to fire an event for a picklist value. I'd imagine a picklist wouldn't control any other components in my case
    – EricSSH
    Aug 28, 2017 at 17:43
  • @EricSSH - All depends on your use case. I have also had issues passing values from classes etc but individual attributes usually work well. It generally works and when it does not there are ways to make it work lol. I'll add the comment as an answer so you can accept if you like
    – Eric
    Aug 28, 2017 at 17:55

1 Answer 1

1

You can pass in an attribute from the parent to the child and use that in the value of the select.

When changed in the child it is automatically propagated to the parent attribute

You must log in to answer this question.

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