I ran into this problem because I used a JavaScript library to restyle checkboxes and it relies on a change event to be fired after the prop "checked" has been changed.
Since this happens most of the time when jQuery is used to set a prop by using jQuery's .prop() function I tried to rewrite this in jQuery like:
$.propHooks.checked = {
set: function(elem, value, name) {
var ret = (elem[ name ] = value);
$(elem).trigger("change");
return ret;
}
};
But ATM tableselect.js is using element.checked = true; what prevents the possibility to do the above.
So I would suggest to either use jQuery to set the prop (see attached patch) or to even fire the change event directly after setting the "checked" prop in vanilla JS.
Comment | File | Size | Author |
---|---|---|---|
#11 | core-js-tableselect-2604912-11.patch | 1.94 KB | stockholmz |
#7 | core-js-tableselect-2604912-7.patch | 1.97 KB | stockholmz |
#3 | core-js-tableselect-2604912-3.patch | 666 bytes | sdstyles |
core-js-tableselect.patch | 630 bytes | pixelmord | |
Comments
Comment #2
droplet CreditAttribution: droplet commentedthe patch exposed a gateway to jQuery but didn't address the main issue. we need to trigger a change event.
Comment #3
sdstyles CreditAttribution: sdstyles at FFW commentedComment #4
stockholmz CreditAttribution: stockholmz as a volunteer commented#3 Patch is great. Fixes the issue, and removes the need for implementing custom jQuery hooks like stated in the bug.
Comment #5
stockholmz CreditAttribution: stockholmz as a volunteer commentedComment #6
droplet CreditAttribution: droplet commentedonly fire event on actually changes. (Needs an if condition)
Comment #7
stockholmz CreditAttribution: stockholmz as a volunteer commentedWe could do something in this direction.
Comment #8
cheatlex CreditAttribution: cheatlex as a volunteer commentedLooks fine to me and when tested on simpletest it din't brake anything
Comment #9
droplet CreditAttribution: droplet commentedcan be simplified.
@see #2603988: Unnecessary ternary condition in toolbar JS
Comment #11
stockholmz CreditAttribution: stockholmz as a volunteer commented#9 - Thanks for the heads up.
Comment #12
mitrpaka CreditAttribution: mitrpaka as a volunteer commentedComment #13
droplet CreditAttribution: droplet commentedComment #14
xjmThanks for the bugfix and thanks @droplet for the subsystem maintainer review and signoff!
Before we commit this to core, can we add steps to reproduce it to the issue? As much as possible they should use only core, but if there's module/etc. code that's needed it'd be good to include that on the issue too. This is especially important since we don't have automated frontend testing yet.
Comment #15
droplet CreditAttribution: droplet commentedIn Drupal, our scripts modified the default HTML behaviours.
Standard:
https://jsfiddle.net/o07vzdu9/
So, if you run the script AFTER PATCH in Drupal in anywhere with Checkbox, you should get the change event.
We should have more confidence on this topic. Especially when we working on Development branch, eg. D8.1 in future. From my experience, I can see most of JS errors come from PHP / Twig code refactoring more than JS changes itself.
In past day, I've spent few years in D8.0. However, I think most of my job can be done with 1 ~ 3 months. Our process now is very inefficiency IMO. We should think about it if we wanna a better Drupal frontend in future.
( Although I don't work on CSS in Drupal a lot, I think there have same problems. Even worse than JS IMO. )
Comment #16
droplet CreditAttribution: droplet commentedComment #17
catchThanks for the steps to reproduce.
Committed/pushed to 8.1.x and cherry-picked to 8.0.x. Thanks!