I fiddled with this while having supper, and this solution works.
HTML:
<div class="spell_tabs">
<input type="radio" name="attr_spell_tabs" value="-1">
<input type="radio" name="attr_spell_tabs" value="0">
<input type="radio" name="attr_spell_tabs" value="1">
<input type="radio" name="attr_spell_tabs" value="2">
<input type="radio" name="attr_spell_tabs" value="3">
<input type="radio" name="attr_spell_tabs" value="4">
<input type="radio" name="attr_spell_tabs" value="5">
</div>
<fieldset class="repeating_spells">
<input type="hidden" class="toggle-show" name="attr_spell_show" value="1">
<div class="spell-display">
<label>Level <span name="attr_spell_level"></span></label>
<select name="attr_spell_level">
<option selected>-1</option>
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</div>
</fieldset>
CSS
div.sheet-spell-display {
display:none;
}
input.sheet-toggle-show[value="1"] ~ div.sheet-spell-display {
display: inline-block;
}
Sheet worker
on('change:spell_tabs', () => {
getSectionIDs('repeating_spells', idarray => {
const fieldnames = [];
idarray.forEach(id => {
fieldnames.push(`repeating_spells_${id}_spell_level`);
});
getAttrs(['spell_tabs', ...fieldnames], v => {
const output = {};
const level = +v.spell_tabs||0;
idarray.forEach(id => {
const thislevel = +v[`repeating_spells_${id}_spell_level`] || 0;
output[`repeating_spells_${id}_spell_show`] = (level === -1 || level === thislevel) ? 1 : 0;
});
setAttrs(output);
});
});
});
So, I have a set of radio buttons at the top for choosing spell level: they set the value of a spell_tabs attribute. They dont have to be radio buttons. You could use action buttons or any other approach, so long as a single attribute (named spell_tabs in this example) is set to the level you want to display.
Then in the fieldset, you have a hidden attribute named spell_show, and the bulk of the fieldset row inside a div. Inside that div is an attribute for the spell_level.
Remember that every attribute on a repeating section is unique: this attribute's full name is repeating_spells_ID_spell_show.
So the sheet worker checks whenever spell_tabs changes, and and loops through the repeating section to check the spell level of that row. The matching follows these rules:
set the spell_show attribute to 1 IF
- the spell_tabs attribute is -1 (a setting to show all spells), or
- the spell_level = spell_tabs (the spell level is the same as the tab selected)
And the CSS rule hides the section if the spell_show is 0, and shows it if 1.
Note the spell_show attribute needs a default value of 1, or any new spells you try to create will be hidden!
See if this works for you.
Note: new spells wont be hidden, until you change the spell tabs again. That could easily be changed - either the spell level or some other value in the section could trigger the sheet worker to calculate spell_show, so that it updates automatically. just add that the the sheet worker line like so
on('change:spell_tabs change:repeating_spells:spell_level', () => {
But you want to be careful here- players could accidentally hide a spell before they finish entering the details. So having a button to say "finished entering spell details" or similar, they can click finish and then it will be hidden if it doesnt match the active spell level.