I have a list of options, with a hardcoded standard message option (disabled), which will show if there is nothing selected. Upon clicking the list, you can manually select any option that is not the hardcoded one.
If however, after loading in the data from SalesForce, I have an ID corresponding to the option list, then I want to select that one automatically instead of the hardcoded (disabled) message option.
How do I do this?
Markup:
<aura:attribute name="item" type="CustomItem__c" />
<aura:attribute name="campaigns" type="Campaign[]" />
<ui:inputSelect aura:id="campaignID" class="slds-select">
<ui:inputSelectOption text="" label="Select a campaign:" disabled="true" />
<aura:iteration items="{!v.campaigns}" var="campaign">
<ui:inputSelectOption text="{!campaign.Id}" label="{!campaign.Name}" />
</aura:iteration>
</ui:inputSelect>
Controller code:
loadCustomItem : function(component, event, helper) {
var action = component.get("c.getItem");
var itemID = event.getParam("item");
action.setParams({"itemID" : itemID});
action.setCallback(this, function(response) {
var state = response.getState();
if (component.isValid() && state === "SUCCESS") {
component.set("v.item", response.getReturnValue());
//select the right campaign
} else {
console.log("Failed with state: " + state);
}
});
$A.enqueueAction(action);
},
CustomItem__c is an sObject with a bunch of custom fields, among which a lookup to Campaign (called campaignID__c). How do I, inside the callback function, tell the inputSelect to display the option with the given ID instead of the disabled one? (I'm keeping the question generalized, as I also have to do this for other sObjects.)