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

Automatic fill repeating fieldset in Character sheet?

Hello, i'm into creating a custom character sheet but before i'm diving into the JS programming i just want to look into the API and check if my idea's are working: So, we played "Das Schwarze Auge" (yes, i know it exists a character sheet for that) and that have a TON (one player has 128 Talents, each Talent has 3D20 to roll against a specific value. Yeah... Nice, right?) of Talents and my plan is just to create a character sheet which will be filled from a JSON object into the character sheet but with that huge amounts of Talents it will be a pretty pain to Copy&Paste them so my thought was using the repeating fieldset with the Add and Modify functions. I mean that will be perfect, just hit the Add-Event and fill the data. Well, that's the plan in theory, but how it will look in practical? I dive into the API and it looks that is not possible to achieve that in particular. Does one of the code gurus have an answer or a solution?  I totally need feedback on this and i'm totally open for another way to implement the Characters!  P.S. Yes i used the search with terms like "trigger fieldset event", "trigger fieldset" and also using alot of Google but it just show's Wikipages or confusing othersites with JS snippets. So sorry if i miss some threads!
1531312739
Jakob
Sheet Author
API Scripter
I can think of a number of ways to do that (I have personally implemented 1. and 2.): Have some kind of <select> outside the repeating section containing all the talent names, plus a "button" (=checkbox) next to it which, when clicked, will add a new row to the repeating section with all the information about that particular talent. React to changing the name of a talent in the repeating section, and automatically fill in the rest of the section if someone enters the correct talent name. (Variation on 2) Have a <select> inside  the repeating section which fills the row with all the information once a talent is selected. There's no  sheet worker event which is triggered when you press the "add" or "modify" buttons, so you can't really work with those.
1531320603
Finderski
Pro
Sheet Author
Compendium Curator
Jakob, couldn't the API (not Sheet Workers) be used to "import" the JSON file? I thought there were some scripts that do imports from Herolab or something?
1531328297

Edited 1531328326
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Doesn't even have to be an API script. A sheetworker can take the JSON copied as text into a textarea, process it and create everything from that, this is how the herolab importer on the PF Community sheet works.
1531402370

Edited 1531402427
Loki
Sheet Author
Yes, the way Scott C. describes works. I also did it this way in the character sheet I've created. A textarea where the player can paste a character as a JSON object and a script that parses the object one element by one and copies the values into the given fields. Of course this includes the possibility to add elements to repeating rows. In my case I had to do some translations because the JSON object comes from an external character generator that uses his own wording and formatting. So this may be a ton of work to do, but it's the most convenient way for the user to import a character.
Thank you for all that input! <3 I took my time and look at the sheet worker which i before never heard of and that is exacly what i need. Also i'm using the generated data from an external character generator, feed it in my custom converter and boom, fill it in the Character sheet in a import textarea. 
1533561870

Edited 1533562145
I have to revive my thread because i getting some weird "error" if i going to fill up my generated repeating fieldset. First of all: i can generate rows of a repeating fieldset, but the value in them are blank . And that drive me crazy because i tried out every i know about JS to fix it. Here is the a part of the sheet. I separate it from the other stuff (like the JSON Data and the correcting through alot of validation methods) and try to fix this one, but i can't imagine why the heck the data will be not filled. They just blank. I tried to remove Placeholder, adding and removing the value attribute but it show not any effect.  The data will be corrected displayed in console but not in that character sheet. <textarea name="attr_import"></textarea> <fieldset class="repeating_inventory"> <input type="text" name="attr_inventory_inventory-name" placeholder="Name" value="" > <input type="text" name="attr_inventory_inventory-description" placeholder="Description" value=""> </fieldset> <script type="text/worker"> const fillRepeatingSection = (sectionName, data) => { let id = generateRowID(); let attr = {}; for(let key in data) { console.log(key, data[key], 'to', `repeating_${sectionName}_${id}_${sectionName}-${key}`); attr[`repeating_${sectionName}_${id}_${sectionName}-${key}`] = data[key]; } console.log(attr); setAttrs(attr); }; on('change:import', function(e) { let testCategory = 'inventory'; let testData = []; testData['name'] = 'Foo'; testData['description'] = 'Bar'; console.log("#####################"); console.log(testCategory, testData); fillRepeatingSection(testCategory, testData); }); </script> The console generated the right data with the corrected id:  repeating_inventory_-LJEOZof7FpPpqH5VCm3_inventory-description : " Bar " repeating_inventory_-LJEOZof7FpPpqH5VCm3_inventory-name : " Foo " I loose my mind on this one. 
1533599978
Jakob
Sheet Author
API Scripter
Looks like your html has a duplicated "inventory", because you have " attr_inventory_inventory-name " instead of " attr_inventory-name ", same for the description.
1533620731

Edited 1533620776
I change it to "attr_inventory-name" but it still doesn't feed the testData into the fieldset. It still creates a blank row. Also i changed it back to attr_inventory_name. Another blank row without data. Also if i change  attr[`repeating_${sectionName}_${id}_${key}`] = data[key]; to (repeating_inventory_-ID-name) attr[`repeating_${sectionName}_${id} - ${key}`] = data[key]; It just gives me an error, so that doesn't unfortunately do the trick.
1533624554
GiGs
Pro
Sheet Author
API Scripter
I don't know if this is the problem, but it's a good idea to avoid - characters in attribute names you'll be using in complex sheet worker scripts. Try changing inventory-name to inventoryname, and do the same with the other attributes, and see if it works.
Yes! It worked!  Thank you G G!  But doesn't that make the setAttrs()-Function not full functional? If we take a look the Wiki  it clearly says: var newrowid = generateRowID (); var newrowattrs = {}; newrowattrs[ "repeating_inventory_" + newrowid + "_weight" ] = "testnewrow" ; setAttrs (newrowattrs); So ... yes, it worked, it was clearly my fault to use underscores. Maybe just a preg_match-Thing in the setAttrs i guess. 
1533628658

Edited 1533628888
GiGs
Pro
Sheet Author
API Scripter
Underscores should be fine. It's the hyphens that are a problem. So inventory-name can cause issues, but inventory_name should be fine. I suggested inventoryname (without underscores) for clarity mainly - those repeating fieldset names already have so many underscores they can be hard to parse visually. Also repeating_ is a special case - roll20 knows there will be an underscore there, as well as one on either side of the ID. So even if underscores did generally cause an issue, those three would always be fine, because they are required.