web-components icon indicating copy to clipboard operation
web-components copied to clipboard

[checkbox] Only first item in checkbox group remains "checked"

Open moderndeveloperllc opened this issue 6 years ago • 4 comments

Description

For some instances of checkbox-group that is programatically created, if all boxes are checked, Polymer will uncheck everything but the first box in it's element async updater. I have others that are working fine, but the below example just breaks.

Expected outcome

All checkbox should be checked

Actual outcome

Only first checkbox

Live Demo

https://glitch.com/edit/#!/subsequent-sumac

moderndeveloperllc avatar Sep 23 '19 21:09 moderndeveloperllc

That's interesting. Can not confirm it locally but something is apparently broken.

web-padawan avatar Sep 30 '19 13:09 web-padawan

@web-padawan It's rather vexing in that I had two loops in the same component - one worked fine, one didn't. I was able to work around the issue by not looping through the individual checkboxes and setting .checked = true, but by setting the .value of the checkbox group afterwards. That works in my case because I'm defaulting to everything being checked.

   for (const stat of orderStatus) {
     const filterCheckbox = document.createElement('vaadin-checkbox');
     filterCheckbox.innerText = stat;
--   filterCheckbox.checked = true;
     filterCheckbox.setAttribute('value', stat);
     deliveryCheckboxGroup.append(filterCheckbox);
   }
++ deliveryCheckboxGroup.value = orderStatus;

I stepped through the JS execution. All the checkboxes are set properly until Polymer's property update when they become unchecked. I'm not experienced enough in the Polymer internals to properly debug at that point. The fact that it works sometimes, but not others makes me feel like it's an async timing issue, somehow.

moderndeveloperllc avatar Sep 30 '19 13:09 moderndeveloperllc

@web-padawan FYI, this is still an issue it looks like an issue when setting the values of a checkbox group on a checkbox-by-checkbox value.

moderndeveloperllc avatar May 24 '20 20:05 moderndeveloperllc

I can confirm, this is still an issue at current version (3.0.0). Workaround by setting .value on group element works.

filip-paczynski avatar Mar 01 '21 21:03 filip-paczynski