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
In the template for my actor sheet I have a checkbox like so
that works just fine. I can check it and see on the actor the property is changed.
Then I have a list of identities
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:
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 appreciated6 Replies
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
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.
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
@Nova the snuccubus gave :vote: LeaguePoints™ to @Ethaks (#8 • 397)
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.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!