Updating Owned Item

Hi! I'm making a character sheet for a new system and I'm having issues having the sheet update properties on an Owned item. For a simplified version of what I'm doing I have an actor type called Girl with a data model schema like {test: new BooleanField({required: true, initial: false})} and an item type called Identity with a data model schema like {marked: new BooleanField({required: true, initial: false})} I have created a Girl and an Identity with its parent set to the Girl. So far so good in prepareContext on the actor sheet I define among others
return {
system: this.actor.system,
identities: this.actor.items
}
return {
system: this.actor.system,
identities: this.actor.items
}
In the template for my actor sheet I have a checkbox like so
<input type="checkbox" name="system.test" {{checked system.test}}>
<input type="checkbox" name="system.test" {{checked system.test}}>
that works just fine. I can check it and see on the actor the property is changed. Then I have a list of identities
<ol class="item-list">
{{#each identities as |identity id|}}
<li
class="item flexrow"
data-item-id="{{identity.id}}"
data-document-class="Item"
>
<div class="item-name">
{{identity.name}}
</div>
<!-- ... checkbox goes here -->
</li>
{{/each}}
</ol>
<ol class="item-list">
{{#each identities as |identity id|}}
<li
class="item flexrow"
data-item-id="{{identity.id}}"
data-document-class="Item"
>
<div class="item-name">
{{identity.name}}
</div>
<!-- ... checkbox goes here -->
</li>
{{/each}}
</ol>
That renders just fine too. But just like with the checkbox on the Actor itself I want a checkbox that can modify the owned item without having to open the Item sheet and editing the doc that way. This is what I cannot figure out. I expected this to work:
<input
type="checkbox"
name="system.marked"
{{checked system.marked}}
data-item-id="{{identity.id}}"
>
<input
type="checkbox"
name="system.marked"
{{checked system.marked}}
data-item-id="{{identity.id}}"
>
But it does not. It renders a checkbox yes, but checking it does not update the item when checked. Closing the sheet and opening it again reveals the checkbox still unchecked, and using the console to find the item and check its system.marked property it is still showing false. What am I missing? Any help is appreciated
6 Replies
Nova the snuccubus
Nova the snuccubusOP2mo ago
Also I'm using foundry version 12 build 331. It's important to me that the system works with v12 as my GM says other systems he hosts don't work in newer versions :shrug3: Also using {{log system}} at the location I'm placing the checkbox I can see that it does in fact have the Identity not the Girl in case that was anyone's inclination Also tried the formInput helper
{{formInput system.schema.fields.marked checked=system.marked data-item-id=system.id}}
{{formInput system.schema.fields.marked checked=system.marked data-item-id=system.id}}
Ethaks
Ethaks2mo ago
Foundry's document sheet handling only ever updates the underlying document with form data, not anything embedded into it. You'll have to write your own listener for change events you want to forward to an embedded document.
Nova the snuccubus
Nova the snuccubusOP2mo ago
interesting! Even in V2? Thanks though. So there's no "help" for this I'll just have to put my own listeners in the javascript and send calls to update manually? I had a dropdown work for a while without doing so though it also broke without me realizing when it stopped working so idk I feel like maybe for my use case it'll end up easier abandoning the items concept for anything that doesn't need to be in a compendium at that point. A shame
Leo The League Lion
@Nova the snuccubus gave :vote: LeaguePoints™ to @Ethaks (#8 • 397)
Ethaks
Ethaks2mo ago
The easiest approach is to give inputs whose changes you want to forward some attribute like data-name, and then attach a change listener in _onRender that checks for that marker (and some id for the embedded document in some parent element) and then stops the event propagation/default and issues the update call.
Nova the snuccubus
I'll try that Yep that worked! Thank you very much. Looking at the system I was using for reference they too had done exactly that, so that's what I was missing! Thank you for your help!

Did you find this page helpful?