For a picklist field, it is possible within Object Manager, to select one picklist value as the default value, so that for new records this field is automatically selected in the dropdown.
I want to show a picklist field on a lwc using a lignting combobox. Is it possible using the lwc framework to assign the correct default picklist value?
I used:
import { getObjectInfo, getPicklistValues } from "lightning/uiObjectInfoApi";
picklistFieldValue;
...
@wire(getPicklistValues, {
recordTypeId: "$someSObject.data.defaultRecordTypeId",
fieldApiName: SOME_PICKLIST_FIELD,
})
setPicklistValues({ data, error }) {
if (data) {
//How to set the value to the default picklist value?
...
}
}
}
There however seems to be no method or field I can use that is provided.
Any advice or help would be very much appreciated.
Best Answer
The default value, if any, will be in
data.defaultValue
. To avoid possible race conditions, store the value in a property:and bind to the value property: