T

TyphonJS

typhonjs-runtime

Join Server

TJSProseMirror for arrays?

SSolidor2/25/2023
Question about the TJSProseMirror component.

I am trying to pass a fieldname belonging to an object in an array like so:

fieldName={system.rulesElement[${idx}].message}

However, what this ends up doing is creating a new key in my document "rulesElement[0]":

How would I pass it a fieldname with an array index?
MMLeahy2/25/2023
I'm not sure exactly.. It doesn't look like that is possible. foundry.utils.getProperty is utilized to read the property from the document, so whatever is allowed there. A quick look at it and it doesn't seem to support array indexing; just indexing a nested object. Saving data is accomplished with: $doc.update({ [options.fieldName]: data }).

If you need array indexing you might need to handle serializing the data externally in a custom wrapper component.
SSolidor2/26/2023
No worries. I ended up wrapping it like so.

<div class="editor">
   <TJSProseMirror
      bind:content={value}
      on:editor:save={() => {
         $document.update({
            system: $document.system,
            flags: $document.flags,
         });
      }}
   />
</div>