Check box not linked to the property

Hello, I am using boilerplate but currently I am having an issue with linking my checkbox using handlebars. I have created json property equipped for weapon. I have created a listener but in no way I am able to make it work. So the in the actor sheet box automatically unchecks after update. and console log does not register anything Can anyone please give me advice on how to solve this or show how the handlebars should be working for checkbox on Foundry? This is my .hbs file code snippet <input type="checkbox" name="system.item.weapon.equipped" class="equip-toggle" title="Equip Weapon" data-dtype="Boolean" data-item-id="{{item._id}}" {{checked system.item.weapon.equipped}} />
4 Replies
Kristov
Kristov23h ago
I think the error could be : {{checked system.item.weapon.equipped}} Is system.item.weapon.equipped returned by your getData() ? Use {{log this}} in your template to see your hbs context and if system.item.weapon.equipped exists Are you sure also about your name ? It's about an item ? what is the data structure of it ?
Kalltern
KallternOP16h ago
Thanks for the reply. I was only using a listener, not getData() When I used {{log this}} it actually did retrieve information about the object. that the status is equipped false. it also randomly switched to true but that status does not change no matter if I check or uncheck the box With the name, no I am not sure :D. I used previously only item.equipped but it did not do anything so I started to try everything. Yes it is an item type weapon. The structure is following "Item": { "types": [......"weapon"], "htmlFields": ["description"], "weapon": { . .. "equipped": false, With the item name, and checked I had this for the first time {weapon.equipped} but then I realised the whole thing is inside {{#each weapon as |item id|}} So i tried to use item but it also did not work
Ethaks
Ethaks15h ago
Foundry's form handling will only update the document that the sheet is for, not embedded/descendant documents like Items owned by the actor. So for above case, the actor's source data would get updated, not the item that's meant to receive the update. To update an embedded item, you'll have to manually pass through such data, bypassing the normal form handling. The gist of it would be to remove the name attribute and replace it with e.g.data-property, and then add a change listener in the sheet that retrieves the relevant item via id and the field/property path as well as the input value from the input, and then forwards that to the item via update.
Kalltern
KallternOP15h ago
Aha! I do not really seek to update the item specifically. the whole idea was to apply the items effects for the character if it is equipped I only introduced the equipped boolean later because the check box would not want to stay checked
Want results from more Discord servers?
Add your server