Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×

JQuery on handler question

I'm working on a custom sheet, which has several repeating sections.  I can overlay the Edit and Add buttons with my own icons, and replace the add button function.  All of that works.  But what I'm trying to do now is detect when Edit is clicked so I can tell if a given section is in editmode so I can disable my Add function (there doesn't appear to be any way to detect that the "editmode" class was added to the repcontainer). I should note that I'm not a particularly adept javascript programmer (I know C), and my CSS knowledge is even more sketchy, so I could easily be missing something simple. I noticed that $20 can be used to create an "on" handler, as well as detecting a specific repeating section using the groupname, but when I tried combining these, it doesn't work, and I'm not sure if I'm just doing something wrong, or if this is more complex syntac than $20 supports. What I've specifically got is a handler to detect a click on the standard repcontrol_edit button by the user.  A simple version works for every repeating section, but the event doesn't provide information that identifies the specific section: $20(`.repcontrol_edit`).on("click", (event) => {     console.log("on(click, repeating_attacks:edit): Enter");     log(event); }); But when I try to make the selector more specific, to identify the edit button that's the child of the "repeating_attacks" repcontrol div, the handler never fires: $20(`.repcontrol[data-groupname="repeating_attacks"] > .repcontrol_edit`).on("click", (event) => {     console.log("on(click, repeating_attacks:edit): Enter");     log(event); }); So, any pointers on what I'm doing wrong, or is this just beyond $20's capabilities? And in the latter case, is there another way to detect the activation/deactivation of edit mode?
Well, I didn't get $20 to work, but I solved my problem using CSS. Now when the player clicks edit, add no longer works until they exit edit mode. The trick was to create an invisible (zero opacity) dummy button the same size as my replacement Add button and use CSS triggered off the application of editmode to shift it over the Add button's position at the same time I made Add invisible. This depends on the HTML structure where the div with my controls is a sibling to repcontainer and the buttons are within it.  The specifc CSS involved, for the curious is: /* remove visibility of the add button when in editmode */ .charsheet .editmode[data-groupname=repeating_attacks] ~ .attacks-row-controls .attack-control-action {   opacity: 0.0; } /* dummy button to intercept clicks, margin has to match the grid spacing */ .charsheet .editmode[data-groupname=repeating_attacks] ~ .attacks-row-controls .dummy-control-action {   margin-left: -45px; } The first hides my Add, the second repositions the Dummy so it intercepts any clicks on the location of the Add button.  I use grid, and the -45px is the grid spacing of the buttons. Here's the associated HTML structure:
1788142673
vÍnce
Pro
Sheet Author
Sounds like you got it worked out.  This should work for your jquery attempt $20(`.repcontrol[data-groupname="repeating_attacks"] .repcontrol_edit`).on("click", (event) => { console.log("on(click, repeating_attacks:edit): Enter"); log(event); });
Thanks, I'll give that a try.
1788215154
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
for the css method, you could just add "pointer-events: none;" to the add button when edit mode is on.
I hadn't known about that kind of style, thank you.