How can I support text fields added in render hooks?
dmrickey opened this issue · 7 comments
Is there any way to support text fields that are added via render hooks?
Good question, it probably depends on the order in which the hooks are executed. If the hook adding the field runs before AIP's hook, it should probably work, but otherwise, I don’t really see an option. Unfortunately, it’s not easy to control the order of hooks, it depends on the order in which they are registered. AIP registers its application hooks during the setup hook, so if the field adding hook is registered before that (e.g., during the init hook), it should work. If it does not, I’d need to investigate why, when I’m back from vacation (will be back on Monday, 11.09.).
My hooks are registered during startup of my mod (not in a hook, just in the entry file). Which I think is technically before the init hook? I'm not sure. The system is already supported (pf1) and in my mod I'm registered for the renderItemSheet
hook and adding in more fields.
No rush, at this point it's just a minor annoyance but it'd be nice if I could get something working for this.
Yes, that’s before the init hook, so it should be fine. Then it should be just a matter of making sure that your custom input fields are getting picked up by the configuration for AIP.
You can see the config for the pf1 item sheet here: https://github.com/ghost-fvtt/FVTT-Autocomplete-Inline-Properties/blob/main/src/package-config.js#L230. Most likely, your inputs don’t match those selectors. You can either change your inputs so that they match, or change the configuration to add additional selectors.
To do the latter, you can register for the aipSetup hook, which passes this whole configuration object as parameter to the callback. There, you can modify it inplace, to add the selectors for your inputs. See https://github.com/ghost-fvtt/FVTT-Autocomplete-Inline-Properties/blob/main/CONTRIBUTING.md#adding-a-package-config for more details about the hook.
Hm, I looked at that and thought they should match.. I'll take a closer look
Ok interesting. I did a bit of digging. You're mod is registering for renderItemSheetPF
whereas I'm registering for the slightly more generic renderItemSheet
.
Turning on hook debugging it looks like yours is emitted first.
I wouldn't say either one was wrong. It looks like I can just update mine to use renderItemSheetPF
and then it looks like it will work. But it might be worthwhile to update AIP to use the slightly more generic renderItemSheet
because someone else may do something similar in the future and there probably shouldn't be any difference between them as far as AIP is concerned.
Digging into what foundry is doing - it looks like it fires off "the most specific first" and then fires off up the parent chain.
So specifically for PF, it has a Container item that extends ItemPF which extends Item. So if I open a container sheet, it's going to fire renderItemSheetPF_Container
, then renderItemSheetPF
, then finally renderItemSheet
.
So specifically for AIP it seems like it would want "the parent-most" render hook so it can be sure to catch as much as possible from what was added in previous hooks.
Since the configuration is system specific, I think it makes sense to use the system specific render hook. I really only want to register for the the ItemSheetPf being rendered, in this case, not any other item sheet. So I’ll keep it like this.
Assuming that it works now for you, I’m closing this issue. If there are still any problems, feel free to reopen it.