Skip to content

comboboxify

Import

import { comboboxify } from 'c/bolt';

Usage

export default class myLwc extends LightningElement {
@wire(apexMethod)
apexResults;
get comboboxOptions() {
return this.apexResults?.data
? comboboxify(this.apexResults.data, {
value: ['Relation__c.Field__c'],
label: ['Relation__c.Field__c']
})
: [];
}
}

Methods

comboboxify(data, shape) : Option[]

NameTypeDescription
dataObject[]Array of javascript objects received from any sources
shapeOptionShapeDescription of how you want your options to look like by defining the props label, value and description

Example

Usage of relationship field
export default class myLwc extends LightningElement {
@wire(apexMethod)
apexResults;
get comboboxOptions() {
return this.apexResults?.data
? comboboxify(this.apexResults.data, {
value: ['Relation__c.Field__c'],
label: ['Relation__c.Field__c']
})
: [];
}
}
@auraEnabled(cacheable=true)
public static Case apexMethod() {
return [SELECT Relation__c.Field__c FROM Case];
}
Concatenate values
export default class myLwc extends LightningElement {
@wire(apexMethod)
apexResults;
get comboboxOptions() {
return this.apexResults?.data
? comboboxify(this.apexResults.data, {
value: ['Relation__c.Field__c', 'OtherField__c', 'AnotherOne__c'],
label: ['Relation__c.Field__c']
})
: [];
}
}
@auraEnabled(cacheable=true)
public static Case apexMethod() {
return [SELECT Relation__c.Field__c, OtherField__c, AnotherOne__c FROM Case];
}
Usage of single values
export default class myLwc extends LightningElement {
@wire(apexMethod)
apexResults;
get comboboxOptions() {
return this.apexResults?.data
? comboboxify(this.apexResults.data, {
value: ['$'],
label: ['$']
})
: [];
}
}
@auraEnabled(cacheable=true)
public static String apexMethod() {
return new Array<String>{'OK', 'KO', 'ERROR', 'WARN'};
}