Fetch checkbox value (from within multifield) | Community
Skip to main content
Level 6
Apr 19, 2021 6:15 AM UTC
Solved

Fetch checkbox value (from within multifield)

I need to fetch value of a checkbox which is present in multifield. There is another checkbox and both the checkboxes are having same granite:class. So I am unable to use granite:class to fetch the value of the checkbox. What else ways are possible to fetch the value of the first checkbox?

Cant use this: let ctaDropdown = $(this).find(".cq-dialog-checkbox-showhide")[0].selectedItem.value;

since my other checkbox is also having same class (cq-dialog-checkbox-showhide)

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Asutosh_Jena_
Asutosh_Jena_Accepted solution
New Participant
Apr 19, 2021 6:46 AM UTC

Hi @shaheena_sheikh 

 

You can read the first checkbox value by using the below line of code:

 

var checkValue = $(this).find(".cq-dialog-checkbox-showhide").eq(0).find(".coral3-Checkbox-input").is(":checked")
alert(checkValue);

 

Complete logic will be like this:

(function ($, document, ns) {
$(document).on("dialog-ready", function () {
$(".coral3-Multifield-item").each(function (index) {
var firstCheckValue = $(this).find(".cq-dialog-checkbox-showhide").eq(0).find(".coral3-Checkbox-input").is(":checked")
console.log(firstCheckValue);
})
});
})(Granite.$, document, Granite.author);

Hope this helps!

Thanks 

4 replies

Asutosh_Jena_
Asutosh_Jena_Accepted solution
New Participant
Apr 19, 2021 6:46 AM UTC

Hi @shaheena_sheikh 

 

You can read the first checkbox value by using the below line of code:

 

var checkValue = $(this).find(".cq-dialog-checkbox-showhide").eq(0).find(".coral3-Checkbox-input").is(":checked")
alert(checkValue);

 

Complete logic will be like this:

(function ($, document, ns) {
$(document).on("dialog-ready", function () {
$(".coral3-Multifield-item").each(function (index) {
var firstCheckValue = $(this).find(".cq-dialog-checkbox-showhide").eq(0).find(".coral3-Checkbox-input").is(":checked")
console.log(firstCheckValue);
})
});
})(Granite.$, document, Granite.author);

Hope this helps!

Thanks 

Translate
Level 6
Apr 19, 2021 9:54 AM UTC
what is eq(0)?
Translate