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 .
×
Create a free account

Deleting a repeating section row from the API

1470315504

Edited 1470315921
Tim P.
Sheet Author
API Scripter
I've got a set of repeating sections which represent Critical Injuries. I want to add a button to each section to remove that particular critical (effectively replacing the Modify > Delete functionality). I have a hidden field in each repeating section which contains the section's data-reprowid attribute. I have passed this attribute back to the API and am trying to use getObj and findObjs to find and delete the repeating section but the code is coming up blank when searching for that data-reprowid attribute. I did a findObjs with no attributes and there was no object found which had that id. Is there some way to get access to a repeating section row object to delete it, or otherwise duplicate the Delete functionality in a repeating section? Thanks for moving it. I saw similar questions in Specific Use and mistakenly thought that was a smart place to post this.
1470343193
Lithl
Pro
Sheet Author
API Scripter
The actual name of an attribute in a repeating section is "repeating_name-of-your-repeating-section_rowid_attribute-name". So, for example, you'd have something like "repeating_critical-injuries_-Abc123_description". If you wanted to find all attributes in a given row, you would want something like this: var rowid = ... var character = ... var regex = new RegExp('^repeating_.*?_' + rowid + '_.*?$'); var attrsInRow = filterObjs(function(obj) { if (obj.get('type') !== 'attribute' || obj.get('characterid') !== character.id) return false; return regex.test(obj.get('name')); }); // attrsInRow is an array of all of the attribute objects in the specified row
1470347166
Tim P.
Sheet Author
API Scripter
I can access the attributes okay. What I'm sstruggling with is the actual row itself. If I delete all of the attributes within a row will that also delete the row and remove it from the sheet ?
1470356998
Tim P.
Sheet Author
API Scripter
I reckon I've answered my own question. Using Brian's code above I was able to remove all of the attributes within a repeating section, and the section row itself is then removed from the character sheet. var rowid = critID; var regex = new RegExp('^repeating_.*?_' + rowid + '_.*?$'); var attrsInRow = filterObjs(function(obj) { if (obj.get('type') !== 'attribute' || obj.get('characterid') !== diceObj.vars.characterID) return false; return regex.test(obj.get('name')); }); _.each(attrsInRow, function (attribute) { attribute.remove(); }); The other question I had was whether it is possible hide the Add/Modify controls using CSS. I've tried hiding .repcontrol but it doesn't seem to work. I'm guessing the system is preventing me from doing this ?
Look for .itemcontrol instead.
1470361405
Tim P.
Sheet Author
API Scripter
.itemcontrol is for the individual Move and Trash buttons, it does not let me target the Add and Modify buttons.
.repcontrol_edit and .repcontrol_add Most of these things you can find you by using chrome and right clicking on the element you want and selecting inspect. It will open up the html and css in the dev console.
1470391630

Edited 1470401913
Tim P.
Sheet Author
API Scripter
Perhaps I should clarify. I can hide the elements in the inspector, but it's not picking the same change up if I make it in my stylesheet. Actually I take that back. Hiding them individually seems to work. Strange that hiding the whole repcontrol container didn't work. I figured out where I went wrong. I've spent too much time in LESS-land for work that I was trying to use LESS syntax in the stylesheet, which obviously wasn't going to work.