How to pass checkbox value, marked required and marked enabled/disabled in Salesforce Lightning Web Component (LWC) | set value of checkbox with enabled/disabled and required uses of lightning-checkbox-group tags in lightning web component – LWC

5,202 views

Hey guys, today in this post we are going to learn about How to pass checkbox value, marked required and marked enabled/disabled uses of lightning-checkbox-group tags in Salesforce Lightning Web Component (LWC)

A lightning-checkbox-group component represents a checkbox group that enables selection of single or multiple options.

If the required attribute is set, at least one checkbox must be selected. When a user interacts with the checkbox group and doesn’t make a selection, an error message is displayed. You can provide a custom error message using the message-when-value-missing attribute.

Challenges in your career

🎯 If You Are Facing Any Of These 6 Challenges in your career.

  • Learn Salesforce Development
  • Career Confusion
  • No Interview Call
  • Low Salary
  • No Promotion/Growth
  • No Finding New Job Opportunity
  • Why you stucking from past so many years in same company?

 

If the disabled attribute is set, checkbox selections can’t be changed. To know more details about lightning-checkbox-group, Click Here.

 

 

Files we used to set the value of checkbox in Salesforce LWC β†’

lwcCheckboxGroup.html LWc HTML File Template HTML file to set the value of checkbox in Salesforce Lightning Web Component (LWC)
lwcCheckboxGroup.js LWC JavaScript File It’s hold the checkbox’s label and value throgh Json variable in Salesforce LWC.
lwcCheckboxGroup.js-meta.xml XML Meta File It is used to where this lightning web component file you want to display as lightning__AppPage, lightning__RecordPage, lightning__HomePage.
lwcCheckboxGroupApp.app Lightning Application It is used for call the component and preview on browser.

 

Final Output β†’

set checkbox required disabled and enabled in LWC -- w3web.net

 

 

You can download file directly from github by Click Here.

 
 

Other related post that would you like to learn in Salesforce

  • Find the below steps β–Ύ

 

Create Lightning Web Component HTML β†’

Step 1:- Create Lightning Web Component : lwcCheckboxGroup.html

SFDX:Lightning Web Component >> New >> lwcCheckboxGroup.html

lwcCheckboxGroup.html [Lightning Web Component HTML]

  1.    <template>
  2.     <lightning-card>
  3.         <div class="slds-m-around_medium">
  4.             <h2 class="slds-text-heading_medium"><lightning-icon icon-name="custom:custom86" size="small"></lightning-icon> <strong style="color:#270086; font-size:13px; margin-right:5px;"> How to get checkbox value, marked required and marked disabled in Lightning Web Component (LWC) </strong></h2>
  5.             <br/>
  6.  
  7.             <h3 class="slds-section__title slds-section__title-action">Checkbox Group with Required Selection β†’</h3>
  8.             <br/>
  9.             <lightning-checkbox-group name="Checkbox Group"
  10.                                     label="Required Checkbox Group"
  11.                                     options={options}
  12.                                     value={value}
  13.                                     required></lightning-checkbox-group>
  14.  
  15.                                     <br/>
  16.                                     <h3 class="slds-section__title slds-section__title-action">Disabled Checkbox Group β†’</h3>
  17.                                     <br/>
  18.                                     <lightning-checkbox-group name="Checkbox Group"
  19.                                     label="Disabled Checkbox Group"
  20.                                     options={options}
  21.                                     value={value}
  22.                                     disabled></lightning-checkbox-group>
  23.  
  24.                                     <br/><br/>
  25.                                     <!--Start RelatedTopics Section-->
  26.                             <div style="border:1px #ddd solid; padding:10px; background:#eee; margin:40px 0;">
  27.  
  28.                                         <p data-aura-rendered-by="435:0"><img src="https://www.w3web.net/wp-content/uploads/2021/05/thumbsUpLike.png" width="25" height="25" style="vertical-align:top; margin-right:10px;" data-aura-rendered-by="436:0"><strong data-aura-rendered-by="437:0"><span style="font-size:16px; font-style:italic; display:inline-block; margin-right:5px;">Don't forget to check out:-</span><a href="https://www.w3web.net/" target="_blank" rel="noopener noreferrer" style="text-decoration:none;" data-aura-rendered-by="440:0">An easy way to learn step-by-step online free Salesforce tutorial, To know more Click  <span style="color:#ff8000; font-size:18px;" data-aura-rendered-by="442:0">Here..</span></a></strong></p>
  29.  
  30.                                         <br/><br/>
  31.                                         <p data-aura-rendered-by="435:0"><img src="https://www.w3web.net/wp-content/uploads/2021/07/tickMarkIcon.png" width="25" height="25" style="vertical-align:top; margin-right:10px;" data-aura-rendered-by="436:0"><strong data-aura-rendered-by="437:0"><span style="font-size:17px; font-style:italic; display:inline-block; margin-right:5px; color:rgb(255 128 0);">You May Also Like β†’</span> </strong></p>
  32.                                         <div style="display:block; overflow:hidden;"> 
  33.                                             <div style="width: 50%; float:left; display:inline-block">
  34.                                                 <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  35.                                                     <li><a href="https://www.w3web.net/lwc-get-set-lightning-checkbox-value/" target="_blank" rel="noopener noreferrer">How to get selected checkbox value in lwc</a></li>
  36.                                                     <li><a href="https://www.w3web.net/display-account-related-contacts-in-lwc/" target="_blank" rel="noopener noreferrer">how to display account related contacts based on AccountId in lwc</a></li>
  37.                                                     <li><a href="https://www.w3web.net/create-lightning-datatable-row-actions-in-lwc/" target="_blank" rel="noopener noreferrer">how to create lightning datatable row actions in lwc</a></li>
  38.                                                     <li><a href="https://www.w3web.net/if-and-else-condition-in-lwc/" target="_blank" rel="noopener noreferrer">how to use if and else condition in lwc</a></li>
  39.                                                     <li><a href="https://www.w3web.net/get-selected-radio-button-value-and-checked-default-in-lwc/" target="_blank" rel="noopener noreferrer">how to display selected radio button value in lwc</a></li>
  40.                                                 </ul>
  41.                                         </div>
  42.  
  43.                                         <div style="width: 50%; float:left; display:inline-block">
  44.                                                 <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  45.                                                     <li><a href="https://www.w3web.net/display-account-related-contacts-lwc/" target="_blank" rel="noopener noreferrer">display account related contacts based on account name in lwc</a></li>
  46.                                                     <li><a href="https://www.w3web.net/create-lightning-datatable-row-actions-in-lwc/" target="_blank" rel="noopener noreferrer">how to insert a record of account Using apex class in LWC</a></li>
  47.                                                     <li><a href="https://www.w3web.net/fetch-picklist-values-dynamic-in-lwc/" target="_blank" rel="noopener noreferrer">how to get picklist values dynamically in lwc</a></li>
  48.                                                     <li><a href="https://www.w3web.net/edit-save-and-remove-rows-dynamically-in-lightning-component/" target="_blank" rel="noopener noreferrer">how to edit/save row dynamically in lightning component</a></li>
  49.                                                     <li><a href="https://www.w3web.net/tree-grid-dynamic-expand-collapse-in-lwc/" target="_blank" rel="noopener noreferrer">how to create tree grid with expanded/collapsed section for the entire row in LWC</a></li>
  50.                                                 </ul>
  51.                                             </div>
  52.                                            <div style="clear:both;"></div> 
  53.                                            <br/>
  54.                                             <div class="youtubeIcon">
  55.                                                 <a href="https://www.youtube.com/channel/UCW62gTen2zniILj9xE6LmOg" target="_blank" rel="noopener noreferrer"><img src="https://www.w3web.net/wp-content/uploads/2021/11/youtubeIcon.png" width="25" height="25" style="vertical-align:top; margin-right:10px;"/> <strong>TechW3web:-</strong> To know more, Use this <span style="color: #ff8000; font-weight: bold;">Link</span> </a>
  56.                                             </div>
  57.                                 </div>
  58.  
  59.                             </div>
  60.  
  61.                               <!--End RelatedTopics Section-->
  62.  
  63.             </div>                  
  64.       </lightning-card>                       
  65. </template>

Create Lightning Web Component JavaScript β†’

Step 2:- Create Lightning Web Component : lwcCheckboxGroup.js

SFDX:Lightning Web Component >> New >> lwcCheckboxGroup.js

lwcCheckboxGroup.js [LWC JavaScript File]

  1.   import { LightningElement } from 'lwc';
  2.  
  3. export default class LwcCheckboxGroup extends LightningElement {
  4.     value = [];
  5.  
  6.     get options() {
  7.         return [
  8.             { label: 'Salesforce Aura', value: 'option1' },
  9.             { label: 'Salesforce LWC', value: 'option2' },
  10.             { label: 'Tutorial W3web.net', value: 'option3' },
  11.         ];
  12.     }
  13. }

Create Lightning Web Component Meta XML β†’

Step 3:- Create Lightning Web Component : lwcCheckboxGroup.js-meta.xml

SFDX:Lightning Web Component >> New >> lwcCheckboxGroup.js-meta.xml

lwcCheckboxGroup.js-meta.xml [LWC Meta Data XML]

  1.    <?xml version="1.0" encoding="UTF-8"?>
  2. <LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
  3.     <apiVersion>45.0</apiVersion>
  4.     <isExposed>true</isExposed>
  5.     <targets> 
  6.         <target>lightning__AppPage</target>
  7.         <target>lightning__RecordPage</target>
  8.         <target>lightning__HomePage</target>
  9.     </targets>
  10. </LightningComponentBundle>

Create Lightning Application β†’

Step 4:- Create Lightning Application : lwcCheckboxGroupApp.app

From Developer Console >> File >> New >> Lightning Application

lwcCheckboxGroupApp.app [Component Application File]

  1.    <aura:application extends="force:slds">
  2.     <c:lwcCheckboxGroup/>
  3. </aura:application>

 

Further post that would you like to learn in Salesforce

 


 

FAQ (Frequently Asked Questions)

How do you value a lightning input?

event. target. value returns the field value of lightning-input dynamically.

How do I create a form in LWC?

To customize the form layout or provide custom rendering of record data, use lightning-record-edit-form (add or update a record) and lightning-record-view-form (view a record). The object-api-name attribute is always required, and the record-id is required only when you're editing or viewing a record.

How do you get picklist values based on record type in Apex?

In general, Apex help to get all the picklist field values regardless of record type of on sObject, but the values can be retrieved using the schema class. In general, Apex help to get all the picklist field values regardless of record type of on sObject, but the values can be retrieved using the schema class.

Related Topics | You May Also Like

 
  

Our Free Courses β†’

πŸ‘‰ Get Free Course β†’

πŸ“Œ Salesforce Administrators

πŸ“Œ Salesforce Lightning Flow Builder

πŸ“Œ Salesforce Record Trigger Flow Builder

πŸ‘‰ Get Free Course β†’

πŸ“Œ Aura Lightning Framework

πŸ“Œ Lightning Web Component (LWC)

πŸ“Œ Rest APIs Integration




Hi, This is Vijay Kumar behind the admin and founder of w3web.net. I am a senior software developer and working in MNC company from more than 8 years. I am great fan of technology, configuration, customization & development. Apart of this, I love to write about Blogging in spare time, Working on Mobile & Web application development, Salesforce lightning, Salesforce LWC and Salesforce Integration development in full time. [Read full bio] | | The Sitemap where you can find all published post on w3web.net

Leave a Comment