How to display radio buttons horizontally and create tab from selected radio button value in Lightning Aura Components Salesforce | How to display radio button value in aura:component using JavaScript component controller Salesforce

3,989 views

Hey guys, today in this post we are going to learn about How to display radio buttons horizontally and create tab from selected radio button value in Lightning Aura Components Salesforce.

A ui:inputRadio component represents a radio button whose state is controlled by the value and disabled attributes. It’s rendered as an HTML input tag of type radio. To apply Lightning Design System styling, we recommend that you use lightning:radioGroup instead of ui:inputRadio.

To group your radio buttons together, specify the name attribute with a unique name. To know more details about ui:inputRadio, Click Here β†’.

 

Files we used to display radio buttons horizontally in aura:component β†’

CustomRadioButtonCmp.cmp Lightning Component It is used to display radio buttons horizontally in lightning component
CustomRadioButtonCmpController.js JavaScript Controller It is hold Javascript click function to show/hide container based on radio buttons value.
customRadioButtonApp.app Lightning Application It is used to call the component and preview on browser.

 

 

Final Output β†’

radio buttons value in lightning component -- w3web.net

 

You can download file directly from github by Click Here.

 

Other related post that would you like to learn in Salesforce

  • How to return data from multiple objects using wrapper class in lightning component
  • how to get specific value of custom label in apex class method in Lightning Component Salesforce
  • Custom Validation in a Lightning Input Field on Click Button in Lightning Component Salesforce
  •  

    • Find the below steps β–Ύ

     

    Create Lightning Component β†’

    Step 1:- Create Lightning Component : CustomRadioButtonCmp.cmp

    From Developer Console >> File >> New >> Lightning Component

    CustomRadioButtonCmp.cmp [Lightning Component File]

    1.     <aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    2. 	<aura:attribute name="salesforceLWC" type="boolean" default="false"/>
    3.     <aura:attribute name="auraLightning" type="boolean" default="false"/>
    4.     <aura:attribute name="trigger" type="boolean" default="false"/>
    5.     <aura:attribute name="tutorialW3web" type="boolean" default="false"/>
    6.  
    7.    <div class="slds slds-p-around_large slds-card"> 
    8.        <h2 style="font-size:18px; color:#0000ff;"><lightning:icon iconName="action:preview" size="x-small" alternativeText="Preview" title="Preview" /> Use of Radio Button Functionality in Salesforce Lightning Component [<a href="https://www.w3web.net/" target="_blank" rel="noopener noreferrer">Know more..</a>]</h2><br/>
    9.  
    10.        <div class="slds-grid slds-wrap" style="font-size:16px;">
    11.           <div class="slds-col slds-size_3-of-12"> 
    12.               <ui:inputRadio text="Salesforce LWC" name="radioBtn" label="Salesforce LWC "  change="{!c.radioButtonAction}"/>
    13.            </div>  
    14.  
    15.            <div class="slds-col slds-size_3-of-12"> 
    16.               <ui:inputRadio text="Aura Lightning" name="radioBtn" label="Aura Lightning "  change="{!c.radioButtonAction}"/>
    17.            </div> 
    18.  
    19.           <div class="slds-col slds-size_3-of-12"> 
    20.              <ui:inputRadio text="Trigger" name="radioBtn" label="Trigger "  change="{!c.radioButtonAction}"/>
    21.            </div> 
    22.  
    23.           <div class="slds-col slds-size_3-of-12"> 
    24.              <ui:inputRadio text="Tutorial W3web" name="radioBtn" label="Tutorial W3web "  change="{!c.radioButtonAction}"/>
    25.            </div>          
    26.  
    27.  
    28.  
    29.     </div>
    30.  
    31.     <aura:if isTrue="{!v.salesforceLWC}">
    32.         <div style="padding:15px;">
    33.            <h3 class="slds-text-heading_medium slds-text-color--error"><strong> Salesforce LWC</strong></h3> 
    34.            <p>Enhance your Salesforce users’ experience with customizable Lightning Web Components. Find the Lightning Web Components that are right for you on AppExchange. Connect With Customers. Collaborate Better. Salesforce Admin Tools. To live demo project learn  <span class="readMore"><a href="https://www.w3web.net/tutorial/salesforce-lwc/" target="_blank" rel="noopener noreferrer">more...</a></span></p> 
    35.         </div>        
    36.     </aura:if>
    37.  
    38.     <aura:if isTrue="{!v.auraLightning}">
    39.         <div style="padding:15px;">
    40.            <h3 class="slds-text-heading_medium slds-text-color--error"><strong>Aura Component</strong></h3> 
    41.            <p>The Lightning Component framework is a UI framework for developing web apps for mobile and desktop devices. It's a modern framework for building single-page applications with dynamic, responsive user interfaces for Lightning Platform apps. To live demo project learn  <span class="readMore"><a href="https://www.w3web.net/tutorial/lightning-component/" target="_blank" rel="noopener noreferrer">more...</a></span></p> 
    42.         </div>        
    43.     </aura:if>
    44.  
    45.     <aura:if isTrue="{!v.trigger}">
    46.         <div style=" padding:15px;">
    47.           <h3 class="slds-text-heading_medium slds-text-color--error"><strong>Trigger</strong></h3> 
    48.           <p>Write a trigger to update parent account phone number when ever the contact phone number is updated using trigger handler and helper class in Salesforce, To learn <span class="readMore"><a href="https://www.w3web.net/tutorial/" target="_blank" rel="noopener noreferrer">more...</a></span></p> 
    49.         </div>        
    50.     </aura:if>
    51.  
    52.     <aura:if isTrue="{!v.tutorialW3web}">
    53.         <div style="padding:15px;">
    54.            <h3 class="slds-text-heading_medium slds-text-color--error"><strong>Tutorial W3web</strong></h3> 
    55.                 <p>An easy way to learn step-by-step online salesforce free tutorial from <strong>w3web.net</strong>, To learn <span class="readMore"><a href="https://www.w3web.net/tutorial/" target="_blank" rel="noopener noreferrer">more...</a></span></p> 
    56.         </div>        
    57.     </aura:if>
    58.  
    59.  
    60.       <!--Start RelatedTopics Section-->
    61.         <br/><br/>
    62. <div style="border:1px #ddd solid; padding:10px; background:#eee; margin:40px 0;">
    63.  
    64.     <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;"/><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>
    65.  
    66.             <br/><br/>
    67.         <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;"/><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>
    68.             <div style="display:block; overflow:hidden;"> 
    69.                 <div style="width: 50%; float:left; display:inline-block">
    70.                     <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
    71.                         <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>
    72.                         <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>
    73.                         <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>
    74.                         <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>
    75.                         <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>
    76.                     </ul>
    77.             </div>
    78.  
    79.             <div style="width: 50%; float:left; display:inline-block">
    80.                     <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
    81.                         <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>
    82.                         <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>
    83.                         <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>
    84.                         <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>
    85.                         <li><a href="https://www.w3web.net/update-parent-object-from-child/" target="_blank" rel="noopener noreferrer">update parent field from child using apex trigger</a></li>
    86.                     </ul>
    87.                 </div>
    88.                <div style="clear:both;"></div> 
    89.                <br/>
    90.                 <div class="youtubeIcon">
    91.                     <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>
    92.                 </div>
    93.     </div> 
    94. </div>
    95.  
    96.   <!--End RelatedTopics Section-->
    97.  
    98.  
    99.   </div>     
    100. </aura:component>

     

    Create JavaScript Controller β†’

    Step 2:- Create Lightning Component : CustomRadioButtonCmpController.js

    From Developer Console >> File >> New >> Lightning Component >> JavaScript Controller

    CustomRadioButtonCmpController.js [JavaScript Controller]

    1.    ({
    2. 	radioButtonAction: function(component, event, helper) {
    3.         var selected = event.getSource().get("v.text");
    4.  
    5.         if(selected == 'Salesforce LWC'){
    6.             component.set('v.salesforceLWC',true);
    7.         }else
    8.             component.set('v.salesforceLWC',false);
    9.  
    10.  
    11.         if(selected == 'Aura Lightning'){
    12.             component.set('v.auraLightning',true);
    13.         }else
    14.             component.set('v.auraLightning',false);
    15.  
    16.  
    17.         if(selected == 'Trigger'){
    18.             component.set('v.trigger',true);
    19.         }else
    20.             component.set('v.trigger',false);
    21.  
    22.         if(selected == 'Tutorial W3web'){
    23.             component.set('v.tutorialW3web',true);
    24.         }else
    25.             component.set('v.tutorialW3web',false);
    26.  
    27.     },
    28. })

     

    Create Lightning Application β†’

    Step 3:- Create Lightning Application : customRadioButtonApp.app

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

    customRadioButtonApp.app [Component Application File]

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

     

    Further post that would you like to learn in Salesforce

     


     

    FAQ (Frequently Asked Questions)

    What is button group in radio button?

    A radio button group is a container control that holds radio buttons. The radio button group defines the layout for the buttons it contains, including a group title, text alignment for button labels, and whether or not to show a border. You can place a radio button group control within a section control.

    How many radio buttons are in a group?

    Only one radio button in a group can be selected at the same time. The radio group must have share the same name to be treated as a group.

    How do you display output fields in lightning component?

    Use the lightning-output-field component in lightning-record-view-form to display the value of a record field on a Salesforce object. Use the field-name attribute to specify the API field name.

    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