fantasycalendar / FoundryVTT-Tagger

Other
6 stars 4 forks source link

Unable to modify tags on prototype tokens #2

Closed matthewswar closed 3 years ago

matthewswar commented 3 years ago

Opening the prototype token dialog triggers this error which prevents the HTML from being injected into the window on Actors that don't have the flag tagger.tags initially set. The work around is to set the flag by manually invoking actor.update({'token.flags.tagger.tags': ''}) before rendering the dialog.

Here's the full stack trace:

Error: Tagger | undefined | inTags must be of type string or array
[Detected 2 packages: tagger, lib-wrapper]
    at Function._validateTags (module.js:189)
    at Function._applyHtml (module.js:241)
    at Function._handleTokenConfig (module.js:219)
    at _handleRenderFormApplication (module.js:214)
    at Function._call (eval at <anonymous> (libWrapper-consts.js:9), <anonymous>:4:14)
    at Function.call (foundry.js:179)
    at TokenConfig._render (foundry.js:2104)
    at async TokenConfig._render (foundry.js:2736)

I've worked around this by adding the coalescing operator when _validateTags is invoked:

const tags = app?.object instanceof Actor
            ? Tagger._validateTags(getProperty(app?.object, "data.token.flags.tagger.tags"))
            : Tagger.getTags(app?.object?._object);

to

const tags = app?.object instanceof Actor
            ? Tagger._validateTags(getProperty(app?.object, "data.token.flags.tagger.tags") ?? [])
            : Tagger.getTags(app?.object?._object);