Last active
January 24, 2020 16:10
-
-
Save srujan21/1899b1ce0c43c1c8681a3ea77b6390d0 to your computer and use it in GitHub Desktop.
Show Picklist in Lightning component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static List <String> getselectOptions(sObject objObject, string fld) { | |
system.debug('objObject --->' + objObject); | |
system.debug('fld --->' + fld); | |
List < String > allOpts = new list < String > (); | |
// Get the object type of the SObject. | |
Schema.sObjectType objType = objObject.getSObjectType(); | |
// Describe the SObject using its object type. | |
Schema.DescribeSObjectResult objDescribe = objType.getDescribe(); | |
// Get a map of fields for the SObject | |
map < String, Schema.SObjectField > fieldMap = objDescribe.fields.getMap(); | |
// Get the list of picklist values for this field. | |
list < Schema.PicklistEntry > values = | |
fieldMap.get(fld).getDescribe().getPickListValues(); | |
// Add these values to the selectoption list. | |
for (Schema.PicklistEntry a: values) { | |
allOpts.add(a.getValue()); | |
} | |
system.debug('allOpts ---->' + allOpts); | |
return allOpts; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1"> | |
<p> | |
<div class="slds-form-element"> | |
<!--<label class="slds-form-element__label" for="select-01">Reason For Transfer</label> | |
<div class="slds-form-element__control"> | |
<div class="slds-select_container"> | |
<select class="slds-select" id="select-01"> | |
<option value=""></option> | |
<option>Office Realignment</option> | |
<option>Restructuring Open Accounts</option> | |
<option>Other – Please provide details in Comments</option> | |
</select> | |
</div> | |
</div>--> | |
<lightning:select name="select" aura:id="reasons" value="{!v.fReason}" label="Reason For Transfer" onchange = "{!c.interestRateButtonGroup}" > | |
<aura:iteration items="{!v.reasons}" var="reason"> | |
<option value="{!reason}" text="{!reason}"></option> | |
</aura:iteration> | |
</lightning:select> | |
</div> | |
</p> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getReasons : function(component, event, helper){ // call this on load or when evey picklist needs to be filled | |
// Create the action | |
var action = component.get("c.getselectOptions"); | |
action.setParams({ | |
fld : 'Reason_For_Transfer__c' | |
}); | |
action.setCallback(this, function(response) { | |
var state = response.getState(); | |
if (state === "SUCCESS") { | |
component.set("v.reasons", response.getReturnValue()); | |
/*var typesArray = []; | |
for(var type in response.getReturnValue()){ | |
typesArray.push(type) | |
} | |
var opts = []; | |
for (var i = 0; i < typesArray.length; i++) { | |
opts.push({ | |
class: "optionClass", | |
label: typesArray[i], | |
value: typesArray[i] | |
}); | |
} | |
component.set("v.reasons", opts);*/ | |
} | |
else { | |
} | |
}); | |
// Send action off to be executed | |
$A.enqueueAction(action); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment