Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Fetch checkbox value (from within multifield)

Avatar

Level 5

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 5
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