0

Is picklist not supported in lightning data service when using with lightning:input

<lightning:input type="text" label="Description" value="{!v.simpleRecord.Description__c}" />

I need to use Lightning data service but picklist field is not showing? Any inputs?

9
  • Is there a reason you don't want to use lightning:inputField? – Keith C Jun 21 '19 at 12:24
  • are you using lightning:recordViewForm or force:recordData? – Pranay Jaiswal Jun 21 '19 at 12:25
  • @PranayJaiswal: i am using force:recordData – Ankur --- Jun 21 '19 at 12:26
  • @KeithC : it(lightning:inputField) does not render any field when used with force:recordData. – Ankur --- Jun 21 '19 at 12:31
  • 2
    You can achieve same with lightning:recordViewForm – Pranay Jaiswal Jun 21 '19 at 12:37
0

Like others have said, recordEditForm is you best bet. But if you need to get the picklist values separately, you can use the uiAPI to get that without Apex, but you need to provide a Record Type Id - so something like this worked for me to get values for a custom picklist field on Account

//Include Import Reference to Object Info and uiAPI
import { getPicklistValues } from 'lightning/uiObjectInfoApi';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';

//Import object and field references = e.g. custom field for State Values
import ACCOUNT_OBJECT from '@salesforce/schema/Account';
import STATEOFREP_FIELD from '@salesforce/schema/Account.StateOfCoverage__c';

//Get the object info so I can lookup the Record Type Id I want
@wire(getObjectInfo, { objectApiName: ACCOUNT_OBJECT })
    wireObject(result) {
        if (result.data) {
            this.objectInfo = result.data;
            const rtis = this.objectInfo.recordTypeInfos;
            this.accountRTID = Object.keys(rtis).find(rti => rtis[rti].name === 'KW - Member');
          } else if (result.error) {
            this.error = result.error;
          }
    }

//Now look up my Picklist Values
    @wire(getPicklistValues, { recordTypeId: '$accountRTID', fieldApiName: STATEOFREP_FIELD })
    stateOptions;

Then I have a getter to return those to the page

get stateOptionValues() {
    if (this.stateOptions.data) {
        return this.stateOptions.data.values;
    }
}

On the page it looks like this:

 <lightning-layout-item padding="around-small" small-device-size="6">
                <lightning-combobox name="State"
                                    label="State of Representation"
                                    options={stateOptionValues}
                                    value={searchState}
                                    onchange={handleChangeSelectValue}>
                </lightning-combobox>
 </lightning-layout-item>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.