0

I have the following code:

HTML:

<lightning-card title="CHOOSE THE INFORMATION TO SHARE" icon-name="">
    <div class="slds-var-m-around_medium" > 
        <template for:each={treatments} for:item="treatment">
            <lightning-input key={treatment.Id} type="checkbox" label={treatment.Diagnostic__r.Name} value={treatment}> </lightning-input>
        </template>
    </div>
    <div class="slds-m-top_small slds-m-bottom_medium submit">
        <lightning-button variant="confirm" label="Share Information" title="Share Information" 
            onclick={handleShareButton} class="slds-m-right_x-small"> 
        </lightning-button>
    </div>
</lightning-card>

JavaScript:

handleShareButton(){
    const infoToShare = [...this.template.querySelectorAll('lightning-input')].filter(input => input.checked);
    infoToShare.forEach(info => {
        this.arrayInfo.push(JSON.stringify(info.value));
    });
    console.log(this.arrayInfo);
}

When I try sending a parameter like treatment.Name it works but not when I sent the object itself, someone knows why?

Thank you in advance...

2
  • Can you please show us what treatments looks like? is it an object or an array? Also, have you tried using a checkbox group? developer.salesforce.com/docs/component-library/bundle/… Commented Jul 7, 2022 at 21:59
  • 'treatments' is a collection of objects. It looks like the value in lightning-input can only take a primitive parameter and that's why I was getting the error. I had to implement a workaround, so I am only sending the Id of the object in value and that way is working. Instead of value={treatment} in the HTML I added value={treatment.Id} Commented Jul 8, 2022 at 13:53

0

You must log in to answer this question.

Browse other questions tagged .