0

I have a picklist that displays a list of articles, and I want that when an option is selected (by clicking the mouse or the enter key) I can access the value of this option.

For now I have the list here in the component :

<aura:handler name="init" value="{!this}" action="{!c.doInit}" /> 
<aura:attribute name="produitsPossibles" type="AP01_ProduitWrapper[]" />
Code<br/>
<ui:inputSelect class="slds-lookup__search-input slds-input awesomplete">
<aura:iteration items="{!v.produitsPossibles}" var="produitsPossibles">
    <ui:inputSelectOption text="{!produitsPossibles.code}" label="{!produitsPossibles.code}" value="">
    </ui:inputSelectOption>
</aura:iteration>
</ui:inputSelect>

the javascript method doInit :

doInit : function(pComponent, pEvent, pHelper) {

    var vInitProduitsMethod = pComponent.get("c.initProduits");
    var vOptyId = pComponent.get("v.optyId"); 
    vInitProduitsMethod.setParams({ 'pOptyId' : vOptyId });
    vInitProduitsMethod.setCallback(pComponent, function(pResponse) {
        var vState = pResponse.getState(); 
        if (vState == "SUCCESS") { 
            console.log('init products ok');
            pComponent.set("v.produitsPossibles", pResponse.getReturnValue());  

        } else {
            pComponent.set("v.errors", [{ message: "error" }]);
        }
    });
    $A.enqueueAction(vInitProduitsMethod);
},

the apex method used in the javascript :

@AuraEnabled
public static AP01_ProduitWrapper[] initProduits(String pOptyId) {
    if (pOptyId == null) {
        return null;
        //return initialiserListeProduits();
    } 
    List<AP01_ProduitWrapper> vListeProduits = new List<AP01_ProduitWrapper>();
    Opportunity vOpty = [SELECT Id, Pricebook2Id FROM Opportunity WHERE Id = :pOptyId LIMIT 1];
    List<PricebookEntry> vPBEList = [SELECT UnitPrice, ProductCode, Product2Id, Pricebook2Id, Name, IsActive, Id, Modele__c
                                    FROM PricebookEntry 
                                    WHERE Pricebook2Id = :vOpty.Pricebook2Id 
                                    AND IsActive = true];

    for (PricebookEntry vPBE : vPBEList) {
        AP01_ProduitWrapper vProduitAAjouter = new AP01_ProduitWrapper();
        vProduitAAjouter.code = vPBE.ProductCode; 
        vProduitAAjouter.prix = vPBE.UnitPrice;
        vProduitAAjouter.idPBE = vPBE.Id;
        vProduitAAjouter.idProduit = vPBE.Product2Id;
        vProduitAAjouter.coutM2 = vPBE.UnitPrice;
        vProduitAAjouter.modele = vPBE.Modele__c;
        vListeProduits.add(vProduitAAjouter);
    }

    return vListeProduits;
}

For now when I select a product in the picklist, I can't retrieve the value or anything... Do you know what to do for getting this value ?

1 Answer 1

3

Use any event to get the pick list value in controller

<ui:inputSelect class="slds-lookup__search-input slds-input awesomplete" onchange="{!c.someaction}">

in controller part

someaction:function(cmp,event){
var evntsource = event.getSource();
var picklistValue =evntsource.get("v.value"); 
}
2
  • Does that mean you can't possibly obtain the current picklist value of a picklist unless it's on change? Commented Jun 6, 2017 at 21:19
  • You can obtain the pick list value using with aura:id also in different function not in init function
    – Raj_SFDC
    Commented Jun 7, 2017 at 10:13

You must log in to answer this question.

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