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 →
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 Component →
Step 1:- Create Lightning Component : CustomRadioButtonCmp.cmp
From Developer Console >> File >> New >> Lightning Component
CustomRadioButtonCmp.cmp [Lightning Component File]
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<aura:attribute name="salesforceLWC" type="boolean" default="false"/>
<aura:attribute name="auraLightning" type="boolean" default="false"/>
<aura:attribute name="trigger" type="boolean" default="false"/>
<aura:attribute name="tutorialW3web" type="boolean" default="false"/>
<div class="slds slds-p-around_large slds-card">
<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/>
<div class="slds-grid slds-wrap" style="font-size:16px;">
<div class="slds-col slds-size_3-of-12">
<ui:inputRadio text="Salesforce LWC" name="radioBtn" label="Salesforce LWC " change="{!c.radioButtonAction}"/>
</div>
<div class="slds-col slds-size_3-of-12">
<ui:inputRadio text="Aura Lightning" name="radioBtn" label="Aura Lightning " change="{!c.radioButtonAction}"/>
</div>
<div class="slds-col slds-size_3-of-12">
<ui:inputRadio text="Trigger" name="radioBtn" label="Trigger " change="{!c.radioButtonAction}"/>
</div>
<div class="slds-col slds-size_3-of-12">
<ui:inputRadio text="Tutorial W3web" name="radioBtn" label="Tutorial W3web " change="{!c.radioButtonAction}"/>
</div>
</div>
<aura:if isTrue="{!v.salesforceLWC}">
<div style="padding:15px;">
<h3 class="slds-text-heading_medium slds-text-color--error"><strong> Salesforce LWC</strong></h3>
<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>
</div>
</aura:if>
<aura:if isTrue="{!v.auraLightning}">
<div style="padding:15px;">
<h3 class="slds-text-heading_medium slds-text-color--error"><strong>Aura Component</strong></h3>
<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>
</div>
</aura:if>
<aura:if isTrue="{!v.trigger}">
<div style=" padding:15px;">
<h3 class="slds-text-heading_medium slds-text-color--error"><strong>Trigger</strong></h3>
<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>
</div>
</aura:if>
<aura:if isTrue="{!v.tutorialW3web}">
<div style="padding:15px;">
<h3 class="slds-text-heading_medium slds-text-color--error"><strong>Tutorial W3web</strong></h3>
<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>
</div>
</aura:if>
<!--Start RelatedTopics Section-->
<br/><br/>
<div style="border:1px #ddd solid; padding:10px; background:#eee; margin:40px 0;">
<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>
<br/><br/>
<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>
<div style="display:block; overflow:hidden;">
<div style="width: 50%; float:left; display:inline-block">
<ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;">
<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>
<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>
<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>
<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>
<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>
</ul>
</div>
<div style="width: 50%; float:left; display:inline-block">
<ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;">
<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>
<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>
<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>
<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>
<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>
</ul>
</div>
<div style="clear:both;"></div>
<br/>
<div class="youtubeIcon">
<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>
</div>
</div>
</div>
<!--End RelatedTopics Section-->
</div>
</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]
({
radioButtonAction: function(component, event, helper) {
var selected = event.getSource().get("v.text");
if(selected == 'Salesforce LWC'){
component.set('v.salesforceLWC',true);
}else
component.set('v.salesforceLWC',false);
if(selected == 'Aura Lightning'){
component.set('v.auraLightning',true);
}else
component.set('v.auraLightning',false);
if(selected == 'Trigger'){
component.set('v.trigger',true);
}else
component.set('v.trigger',false);
if(selected == 'Tutorial W3web'){
component.set('v.tutorialW3web',true);
}else
component.set('v.tutorialW3web',false);
},
})
Create Lightning Application →
Step 3:- Create Lightning Application : customRadioButtonApp.app
From Developer Console >> File >> New >> Lightning Application
customRadioButtonApp.app [Component Application File]
<aura:application extends="force:slds" >
<c:customRadioButtonCmp/>
</aura:application>
Further post that would you like to learn in Salesforce
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 |