You need to sign in to do that
Don't have an account?
anil Kumar
Not able to get lightning input type check box values in JS controller
Hi All,
We are replacing ui names space tags with lightning name space tag in the lightning component since they are going to deprecating soon.
We are displaying multiple languages with checkbox’s . When users selects check box language value should update in backend. While using ui:inputCheckbox tag we are able to update the language but if we use lightning:input type="checkbox" language values updating as Boolean value (True) in the back end instead of check box values. Below is the peace of code.
Component :
<aura:attribute name="selectAllLanguages" type="Boolean" default="false" />
<aura:attribute name="languages" type="Object[]" />
<aura:iteration items="{!v.languages}" var="lang">
<lightning:input type="checkbox" value="{!lang.isSelected}" aura:id="boxPackLanguages" />
<!--<ui:inputCheckbox text="{!lang.language}" value="{!lang.isSelected}" aura:id="boxPackLanguages" />-->
</aura:iteration>
JS:
var languagesSelected = false;
var getAllLanguages = component.find("boxPackLanguages");
if(getAllLanguages != null){
//if there's only one language
if (getAllLanguages[0] == null) {
languagesSelected = true;
languages.push(getAllLanguages.get("v.value"));
}
for (var i = 0; i < getAllLanguages.length; i++) {
if (getAllLanguages[i].get("v.value") == true) {
languagesSelected = true;
languages.push(getAllLanguages[i].get("v.value"));
}
}
}
We are replacing ui names space tags with lightning name space tag in the lightning component since they are going to deprecating soon.
We are displaying multiple languages with checkbox’s . When users selects check box language value should update in backend. While using ui:inputCheckbox tag we are able to update the language but if we use lightning:input type="checkbox" language values updating as Boolean value (True) in the back end instead of check box values. Below is the peace of code.
Component :
<aura:attribute name="selectAllLanguages" type="Boolean" default="false" />
<aura:attribute name="languages" type="Object[]" />
<aura:iteration items="{!v.languages}" var="lang">
<lightning:input type="checkbox" value="{!lang.isSelected}" aura:id="boxPackLanguages" />
<!--<ui:inputCheckbox text="{!lang.language}" value="{!lang.isSelected}" aura:id="boxPackLanguages" />-->
</aura:iteration>
JS:
var languagesSelected = false;
var getAllLanguages = component.find("boxPackLanguages");
if(getAllLanguages != null){
//if there's only one language
if (getAllLanguages[0] == null) {
languagesSelected = true;
languages.push(getAllLanguages.get("v.value"));
}
for (var i = 0; i < getAllLanguages.length; i++) {
if (getAllLanguages[i].get("v.value") == true) {
languagesSelected = true;
languages.push(getAllLanguages[i].get("v.value"));
}
}
}
Have you tried checking with lightning:checkboxGroup once, below is the link to the documentation link,
>> https://developer.salesforce.com/docs/component-library/bundle/lightning:checkboxGroup/example
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.
Thank you for your reply.
I have tried using checkboxGroup checkboxes are not coming . I want use this tag inside aura iteration.
Thanks,
Anil Kumar