5

Want to update checkbox based on toggle option in LWC Salesforce.

<lightning-input type="checkbox" label=" " name="Active" onclick={handleChange}></lightning-input>
5
  • 1
    What have you tried so far? and can you define what toggle option means? – RedDevil Apr 25 '19 at 11:32
  • 2
    What have you tried so far? Where are you stuck? It'll help if you edit your question to include more details and the code that you've written so far. – Derek F Apr 25 '19 at 11:32
  • <lightning-input type="checkbox" label=" " name="Active" value={selectedStatus} onclick={handleChange}></lightning-input> – user65347 Apr 25 '19 at 11:36
  • want js code to fetch actions and save in salesforce database – user65347 Apr 25 '19 at 11:37
  • Added code but you should go through LWC documentation.It has the information you are looking for – RedDevil Apr 25 '19 at 11:45
9

Check this documentation link in LWC which has example of what you are asking for

<!-- helloConditionalRendering.html -->
<template>
    <lightning-card title="HelloConditionalRendering" icon-name="custom:custom14">
        <div class="slds-m-around_medium">
            <lightning-input type="checkbox" label="Show details" onchange={handleChange}></lightning-input>
            <template if:true={areDetailsVisible}>
                <div class="slds-m-vertical_medium">
                    These are the details!
                </div>
            </template>
        </div>
    </lightning-card>
</template>

Code to toggle is in the below js file

// helloConditionalRendering.js
import { LightningElement, track } from 'lwc';

export default class HelloConditionalRendering extends LightningElement {
    @track areDetailsVisible = false;

    handleChange(event) {
        this.areDetailsVisible = event.target.checked;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.