0

Related to a previous question but with a reproducible example, i just can't seem to set the value of any picklist fields when using lightning:inputField, any ideas?

Component

<aura:component implements="flexipage:availableForRecordHome, force:hasRecordId">
    <div class="slds-p-bottom_large slds-p-left_large" style="width:500px">
        <lightning:recordEditForm aura:id="recordViewForm" 
                                     recordId="{!v.recordId}"
                                     objectApiName="Contact">
            <lightning:messages />
            <lightning:inputField fieldName="FirstName" />
            <lightning:inputField fieldName="LastName" aura:id="lastname"/>
            <lightning:inputField fieldName="Birthdate" />
            <lightning:inputField fieldName="Phone" />
            <!--Picklist-->
            <lightning:inputField fieldName="Country__c" aura:id="Country__c"/>
            <lightning:button label="Update" variant="brand" onclick="{!c.update}"/>
        </lightning:recordEditForm>
    </div>    
</aura:component>

Controller

({    
    update: function(component, event, helper) {
        //alert(component.find("Country__c"));
        component.find("Country__c").set("v.value", "Ireland");
    },

})
4
  • 1
    <lightning:inputField fieldName="LeadSource" aura:id="LeadSource" value=""/>
    – Ysr Shk
    Commented Jun 1, 2018 at 11:16
  • 1
    ^Adding value attribute to the picklist will work with the same code.
    – Ysr Shk
    Commented Jun 1, 2018 at 11:17
  • 1
    @YsrShk that worked! if you add it as an answer i'll accept it
    – paul
    Commented Jun 1, 2018 at 21:48
  • Paul, can you edit your original question with this example data please? Never mind - I did it. Add the answer and I will delete this question. Commented Jun 2, 2018 at 0:51

1 Answer 1

2

<lightning:inputField fieldName="LeadSource" aura:id="LeadSource" value=""/>

Please add an Value attribute to the inputfield component.

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