0

How we can read the lightning-combobox key value, In the below i can able to read the value by event.detail.value

How we can read the label value, tried event.detail.label it's Undefined.

  get options() {
        return [
            { label: '1', value: 'new' },
            { label: '2', value: 'inProgress' },
            { label: '3', value: 'finished' },
        ];
    }
<template>
    <lightning-combobox
            name="progress"
            label="Status"
            value={value}
            placeholder="Select Progress"
            options={options}
            onchange={handleChange} ></lightning-combobox>

    <p>Selected value is: {value}</p>
</template>
import { LightningElement } from 'lwc';

export default class ComboboxBasic extends LightningElement {
    value = 'inProgress';

    get options() {
        return [
            { label: '1', value: 'new' },
            { label: '2', value: 'inProgress' },
            { label: '3', value: 'finished' },
        ];
    }

    handleChange(event) {
        this.value = event.detail.value;
       console.log(event.detail.value);
       console.log(event.detail.label);
    }
}

1 Answer 1

2
 const selectedLabel = event.target.options.find(opt => opt.value === event.detail.value).label;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .