Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Fetch checkbox value (from within multifield)

Avatar

Level 6

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)

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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 

View solution in original post

4 Replies

Avatar

Correct answer by
Community Advisor

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 

Avatar

Community Advisor

Hi @Shaheena_Sheikh 

:eq() is a selector that selects an element with a specific index number.

The index number will start at 0, so the first element will have the index number 0.

 

Thanks!

Avatar

Level 6
I have a similar issue with ADD button of multifield. I want to trigger a function when Add button is hit. It was working fine until i had only simple multifield. When i created a nested multifield, if i hit the inner Add button, even then my function gets triggered by the code: $(document).on("click", "button[coral-multifield-add]", function() {}). I want the function to trigger only when i it the outside add button