How to Create & Save Custom Field Values from a Dropdown on Actor sheet?
I am building a custom system for a Hogwarts setting using the Wands & Wizards 5e supplement. I am currently working on the Character Sheets using the boilerplate system, and am trying to add special field properties.
My goal is to have each character sheet feature 3 dropdown bars: 1 for Hogwarts House (Race), 1 for Caster Type (Class), and 1 for School of Magic (Subclass). Depending on the selection, the value will automatically save and store itself in that property, and will be used to pull in features later and set classes within the HTML to change the theme of the character sheet (Red for Gryffindor, Green for Slytherin, etc.).
Currently, the dropdown selections are visible in the actor sheet, but the options do not save and always reset. I'm not sure what I have overlooked to not get this to work. I have attached images of my template.json file, my actor-sheet.html, and the actor-sheet.mjs file. You'll see in the .mjs file that I am trying to console.log() some messages for troubleshooting purposes, but those don't show up at all.
So I am kinda at a loss here and am unsure what to do next. Can anyone help me out? Thank you so much!
9 Replies
It looks to me like they would save just fine. What you do not have is the correct rendering. You are rendering the dropdowns, but you are not selecting the correct option (or any option for that matter).
The
selectOptions
handlebars helper is your friend here.Okay thank you for the advice. I attempted to install a helper to fix this issue and got "some" progress but my issue is not resolved yet. The options for hogwartsHouse are not displaying in the dropdown for the actor sheet (pic 1). The console seems to be correctly loading in the option names and values, however (pic 2). I've included a snippet of the dropdown bar from the actor sheet (pic 3), the helper I wrote in my world.mjs (pic 4), and the data context options that I defined in actor-sheet.mjs (pic 5).
I have also tried using inline-handlebar helpers to assist me, but it constantly throws red errors; I don't think inline is something I can do.
Do you, or anyone else, have additional insight on how I can fix this at this point? Thanks in advance!
Why did you make your own when you just needed to use
selectOptions
?
There doesn't seem to be a selectOptions() helper in the boilerplate, which is why I added my own. I made this adjustment, but its still throwing errors. Do you have a copy of the selectOptions() function you're referring to?
It's added by foundry
example above.
Well this is what I have in place right now, but unfortunately, the options still arent rendering in the dropdown; they show up as undefinied.
Per actor-sheet.html:
<select
id="hogwarts-house"
name="system.attributes.hogwartsHouse.value"
>
{{selectOptions hogwartsHouseOptions selected=hogwartsHouse}}
</select>
But this is how it renders in Foundry during testing:
<select id="hogwarts-house" name="system.attributes.hogwartsHouse.value">
<option value="undefined"></option><option value="undefined"></option><option value="undefined"></option><option value="undefined"></option>
</select>
Try just this:
Oh my god, this was it! Thank you soooooo much for your help!! I appreciate it, greatly! Seriously so thankful for the lesson and excited to continue with the system dev.
{{#select}}
is also an option.
You had nothing that actually selected the current value.