0

I currently have a checkbox group in a lightning web component and I have an onchange function setup to handle a selection. I have been reading the documentation, but can't find any information to extract information other than the value. I want to get the APIName which is stored in the name of the lightning-checkbox-group.

https://developer.salesforce.com/docs/component-library/bundle/lightning-checkbox-group/example

Below I have attached the code snippets from my html and js files for what I have tried to do.

<lightning-checkbox-group key={q.APIName}
       name={q.APIName}
       label={q.fieldLabel}
       options={q.options}
       value={q.value}
       onchange={handleChange}
>
    handleChange(e) {
        console.log(e.detail.name);
        console.log(e.detail.value);
        console.log(e.target.name);
        console.log(e.target.value);
        console.log(e.target);
        console.log(e.target.options);
        this.value = e.detail.value;
    }

1 Answer 1

3

Use currentTarget in place of target. You want the name of the lightning-checkbox-group component. target refers to the checkbox you clicked where as currentTarget will give you access to the component on which current-event listener was attached, that is, the checkbox group in this case.

Not only name you can access all other components attributes with currentTarget.

 handleChange(e) {
        console.log(e.currentTarget.name);
  }
1
  • Amazing, thank you! I'm new to JS and LWC so this was a big help!
    – Greg
    Jun 11, 2021 at 17:01

You must log in to answer this question.

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