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

Undefined Error with radio button

Hi, I was creating a custom sheet and ran into a problem. I checked the code line by line and realized that it was caused by a radio button.  Creating a new session room using a custom sheet, and write the following code in the html part. <fieldset> <input type="radio" name="attr_something" value="0" checked >0 <input type="radio" name="attr_something" value="1" >1 <input type="radio" name="attr_something" value="2" >2 <input type="radio" name="attr_something" value="3" >3 </fieldset> Go to the Mods(API) script and write the following code. log("test"); Save Script, Restart API Sandbox, open a new window and enter the game room, I get the following error in Mods page. TypeError: Cannot read properties of undefined (reading 'split') TypeError: Cannot read properties of undefined (reading 'split') at getAttrName (/home/node/d20-api-server/charsheet.js:119:53) at Object.<anonymous> (/home/node/d20-api-server/charsheet.js:140:27) at exports.each (/home/node/d20-api-server/node_modules/cheerio/lib/api/traversing.js:300:24) at getAvailableAttributes (/home/node/d20-api-server/charsheet.js:138:39) at /home/node/d20-api-server/charsheet.js:365:45 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) In the console "test" "Loading character sheet data..." TypeError: Cannot read properties of undefined (reading 'split') TypeError: Cannot read properties of undefined (reading 'split') at getAttrName (/home/node/d20-api-server/charsheet.js:119:53) at Object.<anonymous> (/home/node/d20-api-server/charsheet.js:140:27) at exports.each (/home/node/d20-api-server/node_modules/cheerio/lib/api/traversing.js:300:24) at getAvailableAttributes (/home/node/d20-api-server/charsheet.js:138:39) at /home/node/d20-api-server/charsheet.js:365:45 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) "test" "Loading character sheet data..." TypeError: Cannot read properties of undefined (reading 'split') TypeError: Cannot read properties of undefined (reading 'split') at getAttrName (/home/node/d20-api-server/charsheet.js:119:53) at Object.<anonymous> (/home/node/d20-api-server/charsheet.js:140:27) at exports.each (/home/node/d20-api-server/node_modules/cheerio/lib/api/traversing.js:300:24) at getAvailableAttributes (/home/node/d20-api-server/charsheet.js:138:39) at /home/node/d20-api-server/charsheet.js:365:45 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) All scripts will not work because of this error. The error seems to occur when the Character sheet is loaded. because the message "Starting webworker script" appears in the console when the character sheet is successfully loaded. As you can see, it's very basic code. I don't know why I'm getting this error. Can you help me? Thanks.
1740323628
GiGs
Pro
Sheet Author
API Scripter
fieldsets must have a class name, and will not be recognised without it, like <fieldset class="myradio"> radio buttons in a fieldset might not be what you want (they often dont work the way you expect). Can you describe what you are trying to t?
1740334133
vÍnce
Pro
Sheet Author
Can you use <fieldset> within an API mod?
1740338346
GiGs
Pro
Sheet Author
API Scripter
I have never tried, but I would expect not - the API has to work in the same HTML engine roll20 is using.
1740350572

Edited 1740351496
MR
Pro
GiGs said: fieldsets must have a class name, and will not be recognised without it, like <fieldset class="myradio"> radio buttons in a fieldset might not be what you want (they often dont work the way you expect). Can you describe what you are trying to t? Thank you for your response. When I specify class in the fieldset, I no longer get the Undefined error! but I do get the this error. "ERROR: Unable to find a valid repeating section name for a value inside of a fieldset" "ERROR: Unable to find a valid repeating section name for a value inside of a fieldset" "ERROR: Unable to find a valid repeating section name for a value inside of a fieldset" "ERROR: Unable to find a valid repeating section name for a value inside of a fieldset" Is it recognizing all fieldset as repeating section?  For now, the other scripts don't seem to have any problems running... I was trying to create a tab that changes based on the value of a radio button, for example, something like this.  <fieldset class="somebutton"> <input type="radio" class="color0" name="attr_something" value="0" checked="checked" >0 <input type="radio" class="color1" name="attr_something" value="1" >1 <input type="radio" class="color2" name="attr_something" value="2" >2 <input type="radio" class="color3" name="attr_something" value="3" >3 </fieldset> <input type="hidden" class="change_color" name="attr_something" value="0" > <span class="text">Hello world</span> .change_color[value="0"] ~ span.text { color: #000; } .change_color[value="1"] ~ span.text { color: blue; } .change_color[value="2"] ~ span.text { color: green; } .change_color[value="3"] ~ span.text { color: red; } This works fine for what I want, I just didn't expect to have problems on the script side.
1740360282

Edited 1740360489
GiGs
Pro
Sheet Author
API Scripter
You don't need to use a fieldset for that. And in roll20, fieldsets are always repeating sections. Just create a radio button, set the input for the attribute before the section of HTML you want to change, give it a class, and thats it. If I'm reading your code corretly, just get rid of the fieldset. Replace this: <fieldset class="somebutton"> <input type="radio" class="color0" name="attr_something" value="0" checked="checked" >0 <input type="radio" class="color1" name="attr_something" value="1" >1 <input type="radio" class="color2" name="attr_something" value="2" >2 <input type="radio" class="color3" name="attr_something" value="3" >3 </fieldset> with this: <input type="radio" class="color0" name="attr_something" value="0" checked="checked" >0 <input type="radio" class="color1" name="attr_something" value="1" >1 <input type="radio" class="color2" name="attr_something" value="2" >2 <input type="radio" class="color3" name="attr_something" value="3" >3 If you want to put it in a container, use a div, like so <div class="somebutton"> <input type="radio" class="color0" name="attr_something" value="0" checked="checked" >0 <input type="radio" class="color1" name="attr_something" value="1" >1 <input type="radio" class="color2" name="attr_something" value="2" >2 <input type="radio" class="color3" name="attr_something" value="3" >3 </div> But this will complicate the CSS, so I wouldnt recommend it. (Unless you create a hidden copy of the something attribute, and use that in your CSS. Based on the code above, the class you have on the radio inputs should be change_color , not color0 to color3 .
Wow, I just realized that fieldset is always a repeating section in roll20. The color0, color3 are leftovers from changing things around for test purposes! They don't actually exist, thanks for checking. I'll use your last method, because as you predicted, there is a reason why I need to hide the section with the radio button. Completely solved!  awesome!  THANK YOU SO MUCH!!