function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Leticia Monteiro Freitas 4Leticia Monteiro Freitas 4 

How to know if a input: type radio is checked in lightning component

Hello, 

I'm Trying use a input type radio, and want see if is checked. 
How could I do that?
Raj VakatiRaj Vakati
like this 
 
<lightning:input type="radio" name="select" value="red label="red" onchange="{!c.handleRadioClick}" />
var colorsel= event.source.get("v.label");

 
Raj VakatiRaj Vakati
If you want to do it based on Aura:id try like this
<lightning:input aura:id="inpCk" type="radio" name="select" value="red label="red" onchange="{!c.handleRadioClick}" />


 
var isChecked = cmp.find('inpCk').get('v.checked');
      console.log(isChecked );


var checkVal= cmp.find('inpCk').get('v.value'); 

 
Leticia Monteiro Freitas 4Leticia Monteiro Freitas 4
Raj, I'm trying something like this:
Controller:
var doc = component.find("radioDoc").get("v.checked");
console.log(doc);
Cmp:
 
<li>
                            <span class="slds-radio">
                                <input type="radio" aura:id="radioDoc" checked="true" onclick="{!c.enableField}" id="documentoRadio" name="tipoBusca" value="documentoRadio"/>
                                <label class="slds-radio__label" for="documentoRadio">
                                    <span class="slds-radio_faux"></span>
                                    <span class="slds-form-element__label">Por Documento</span>
                                </label>
                            </span>
                        </li>


 
Raj VakatiRaj Vakati
Use like this  .. i will recommend to use the  lightning:input  insted of input 
 
<aura:component implements="force:lightningQuickAction,force:hasRecordId">
    <li>
        <span class="slds-radio">
            <input type="radio" aura:id="radioDoc" checked="true" onclick="{!c.enableField}" id="documentoRadio" name="tipoBusca" value="documentoRadio"/>
            <label class="slds-radio__label" for="documentoRadio">
                <span class="slds-radio_faux"></span>
                <span class="slds-form-element__label">Por Documento</span>
            </label>
        </span>
    </li>
    
    
</aura:component>
 
({
    enableField: function(component, event, helper) {
        // Prints true or false 
        var doc = component.find("radioDoc").getElement().checked;;
        console.log(doc);
        // prints name 
        var docLabel = component.find("radioDoc").getElement().name;
        console.log(docLabel);
    },
})

 
Raj VakatiRaj Vakati
Let me know if its not working