1

How do I determine which checkbox in a lightning-checkbox-group is unchecked? I want to filter results based on selected checkbox.

I have tried using both lines below in the onchange event

handleIssueAreas(e) {    
        this.issueValue = e.detail.value;
       console.log('issue value '+ this.issueValue);
        
        if(this.issueValue){
                       
            this.searchArray.push(this.issueValue);
            const payload = { searchString: this.searchArray};

            publish(this.messageContext, SEARCH_MESSAGE, payload);
            
        }
        else if(!this.issueValue ){
            
            console.log('Unchecked!' );
            //add the logic here
        }
      
    }
 console.log('checked value ' + e.target.checked);
 console.log('checked value ' + e.detail.checked);

but they are both returning undefined.

Thanks.

1 Answer 1

0

the documentation for the lightning-checkbox-group demonstrates exactly how to do so, code snippet included as well as usage notes. Since you have not shared your template or JS file, it's hard to tell what you are doing wrong.

to get checked values onchange, you can use:

e.detail.value

this will create an array of selecte values which you can use to do whatever.

8
  • I already did that. As you can see in the code updated above. However, the else part is not getting executed when I uncheck the checkbox.
    – Pauline
    May 7, 2021 at 12:34
  • @Pauline, as mentioned in my answer, this will create an array of selected values which you can use to do whatever. Your code does not make any sense, you are checking for an array, and then pushing your array into another array. you are also checking for the checked property, which is non-existent...
    – glls
    May 7, 2021 at 13:53
  • The rest of the code is quite long that is why i did not put it here. There are two components involved. one has several checkbox groups and once a selection is made, the checkbox values are published. So I got the publishing part to work with by getting the e.detail.value.
    – Pauline
    May 7, 2021 at 15:35
  • the second component receives the values and does the filtering. However, the unchecking part is what is not working. I need to send the message on the unchecked checkbox so that i adjust the results on the second component.
    – Pauline
    May 7, 2021 at 15:37
  • you can check the values from the array, if the value is missing, you handle accordingly. not sure what issue you are facing.
    – glls
    May 7, 2021 at 17:23

You must log in to answer this question.

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