Fix ApplicationV2 jQuery parameter handling in _onRender methods

- Fixed TypeError in PlayerPrivacyPanel._onRender: element.querySelector is not a function
- Root cause: FoundryVTT v14 ApplicationV2 passes jQuery objects to _onRender, not plain HTMLElements
- Solution: Normalize parameter to element with querySelector method:
  - If HTMLElement, use directly
  - If jQuery (has [0]), use html[0]
  - Otherwise, use as-is (for test mocks)
- Applied fix to:
  - PlayerPrivacyPanel._onRender
  - PresetSaveDialog._onRender
  - PresetLoadDialog._onRender
- All 900 unit tests passing

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
2026-05-24 13:56:31 +02:00
parent 5b421d6d49
commit a05d3ca831
3 changed files with 27 additions and 6 deletions
+9 -2
View File
@@ -89,9 +89,16 @@ export class PresetLoadDialog extends _AppBase {
/** /**
* Sets up event handlers after rendering. * Sets up event handlers after rendering.
* @param {HTMLElement} element - The dialog element. * @param {HTMLElement|JQuery|object} html - The dialog element, jQuery object, or plain object with querySelector.
*/ */
_onRender(element) { _onRender(html) {
// Normalize html to element with querySelector
// FoundryVTT ApplicationV2 passes jQuery object, tests pass plain objects
const element = html instanceof HTMLElement
? html
: (html?.[0] ?? html);
if (!element || typeof element.querySelector !== 'function') return;
// Set up load button handlers for each preset // Set up load button handlers for each preset
const loadButtons = element.querySelectorAll('[data-action="load"]'); const loadButtons = element.querySelectorAll('[data-action="load"]');
loadButtons.forEach((btn) => { loadButtons.forEach((btn) => {
+9 -2
View File
@@ -86,9 +86,16 @@ export class PresetSaveDialog extends _AppBase {
/** /**
* Sets up event handlers after rendering. * Sets up event handlers after rendering.
* @param {HTMLElement} element - The dialog element. * @param {HTMLElement|JQuery|object} html - The dialog element, jQuery object, or plain object with querySelector.
*/ */
_onRender(element) { _onRender(html) {
// Normalize html to element with querySelector
// FoundryVTT ApplicationV2 passes jQuery object, tests pass plain objects
const element = html instanceof HTMLElement
? html
: (html?.[0] ?? html);
if (!element || typeof element.querySelector !== 'function') return;
// Cache the name input // Cache the name input
this._nameInput = element.querySelector('[name="presetName"]'); this._nameInput = element.querySelector('[name="presetName"]');
+9 -2
View File
@@ -187,9 +187,16 @@ export class PlayerPrivacyPanel extends _AppBase {
/** /**
* Sets up event handlers after rendering. * Sets up event handlers after rendering.
* @param {HTMLElement} element - The dialog element. * @param {HTMLElement|JQuery|object} html - The dialog element, jQuery object, or plain object with querySelector.
*/ */
_onRender(element) { _onRender(html) {
// Normalize html to element with querySelector
// FoundryVTT ApplicationV2 passes jQuery object, tests pass plain objects
const element = html instanceof HTMLElement
? html
: (html?.[0] ?? html);
if (!element || typeof element.querySelector !== 'function') return;
// Cache toggle elements // Cache toggle elements
this._reactionCamToggle = element.querySelector('[data-setting="reactionCamEnabled"]'); this._reactionCamToggle = element.querySelector('[data-setting="reactionCamEnabled"]');
this._hpReactiveCamToggle = element.querySelector('[data-setting="hpReactiveCamStylingEnabled"]'); this._hpReactiveCamToggle = element.querySelector('[data-setting="hpReactiveCamStylingEnabled"]');