
By default, jQuery shouldn't be able to target the content of a repeating section, but with some adjustment, it is possible to do it anyway. first you need to create an action button of class `repeating_roll but name it using `attr_` instead of `act_`, this will allow us to pass it a value using setAttrs HTML < fieldset class = "repeating_skills" > < button class = "repeating_roll two" type = "action" name = "attr_skill_r" value = "@{skill_action}" >
< span class = "title" > < h3 class = "aligned-left" >
< span name = "attr_name" ></ span >
</ h3 >
</ span >
< span class = "para" name = "attr_rank" ></ span >
</ button > Since a button in the chat cannot be used using jQuery (as far as I know) (the listener is onclick, so it will not work if it's triggered in another way), I suggest adding a second button of type roll to be able to use a normal roll using the custom roll parsing trick . Now, to make the roll feasible, we need to set a value for our button when the sheet is first opened (or when a new element is added or removed. SHEETWORKER
// object that has for key the name of the field and for value the name
// of the repeating section
const _repeating_sections={'special_training':'special',
'skill':'skills',
' b ond':'bonds'
};
const changeRepeatingRolls = ( section , element , id ) => { const attrName = `repeating_ ${ section } _ ${ id } _ ${ element } ` ; getAttrs ([ 'character_id' ], ( values ) => { const character_id = values . character_id ; const update = {};
// update for the hidden roll button with CPR update [ ` ${ attrName } _action` ] = `%{ ${ character_id } | ${ attrName } -action}` ;
// update for jQuery
update [ ` ${ attrName } _r` ] = id ; console . info ( update ); setAttrs ( update , { silent : true }, () => { console . log ( `Update repeating ${ element } rolls` ); }); }); };
// same thing but for all the rolls at once on open
const updateRepeatingRollsonOpen = () => { getAttrs ([ 'character_id' ], ( values ) => { const charid = values . character_id ; console . info ( 'Repeating Sections' , _repeating_sections ); Object . entries ( _repeating_sections ). forEach (([ element , section ]) => { getSectionIDs ( section , function ( idarray ) { var update = {}; console . log ( 'section: ' + section + ' element: ' + element + ' idarray: ' + idarray ); idarray . forEach ( id => {
const crp_attr= `%{ ${ charid } |repeating_ ${ section } _ ${ id } _ ${ element } -action}` ;
update [ `repeating_ ${ section } _ ${ id } _ ${ element } _action` ] = crp_attr; update [ `repeating_ ${ section } _ ${ id } _ ${ element } _r` ] = id ; }); console . info ( 'Value of update inside repeating rollUpdate' , update ); setAttrs ( update , { silent : true }, () => { console . log ( 'Repeating Rolls updated' ); console . info ( 'update' , update ); }); getAttrs ( Object . keys ( update ), function ( v ){ Object . entries ( v ). forEach (([ key , value ]) => { console . log ( `key: ${ key } value: ${ value } ` ); }); }); }); }); }); };
// update on change
Object . entries ( _repeating_sections ). forEach (([ element , section ]) => { on ( `change:repeating_ ${ section } ` , ( eventInfo ) => { const id = eventInfo . sourceAttribute . split ( '_' )[ 2 ]; changeRepeatingRolls ( section , element , id ); }); });
// update on open
on('sheet:opened',(eventInfo) => {
updateRepeatingRollsonOpen ();
} After the initialization is done, you can call the roll using. // call all the roll of class repeating_rolls $20 ( 'button.repeating_roll' ). on ( 'click' , e => { // find the id of the roll in the value of the action button
const id = e . htmlAttributes . value ;
// extract the section, it can be used for multiple repeating sections
const section = _repeating_sections [ e . htmlAttributes . name . split ( '_' )[ 1 ]];
// here I was interested in creating a roll where the Modifier query was optional const hasmodifiers = ( e . shiftKey ) ? true : false ; console . info ( `hasmodifiers:` , hasmodifiers ); const queryModifier = ( hasmodifiers ) ? _queryModifier : '0' ;
... some code ... // here is where I call the custom roll parsing inside the jquery with my optional parameter queryModifier
clicked_repeating_skills ( _parameters , _input_names , queryModifier ); }); This is the results in my character sheet as an example