fix: enable TEC event edit field population for manage event page

- Re-enabled HVAC_Event_Edit_Comprehensive class initialization
- Added proper file includes for event edit classes
- Updated JavaScript to wait for TEC form to fully load via AJAX
- Fixed field selectors to match actual form structure
- Increased timeouts to handle AJAX form rendering
- Prioritized correct selectors for form fields

The comprehensive fix now properly loads event data and populates fields
when editing events from the trainer dashboard.

🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Ben 2025-08-18 13:49:09 -03:00
parent 25d5c9ac7d
commit 0f94a42f15
4 changed files with 254 additions and 12 deletions

View file

@ -110,11 +110,11 @@
debugLog('Populating core fields', coreData); debugLog('Populating core fields', coreData);
// Title field // Title field - prioritize the actual selector on the page
if (coreData.title) { if (coreData.title) {
const titleSelectors = [ const titleSelectors = [
'input[name="post_title"]', // This is what's actually on the page
'#post_title', '#post_title',
'input[name="post_title"]',
'.tribe-community-events-form-title input', '.tribe-community-events-form-title input',
'#tribe-event-title' '#tribe-event-title'
]; ];
@ -602,8 +602,18 @@
$(document).ready(function() { $(document).ready(function() {
debugLog('Document ready, initializing comprehensive field population'); debugLog('Document ready, initializing comprehensive field population');
// Wait a bit for TEC form to initialize // Wait longer for TEC form to fully render via AJAX
setTimeout(populateAllEventFields, 1000); setTimeout(function() {
// Check if form exists before populating
if ($('#post_title, input[name="post_title"]').length > 0) {
debugLog('Form detected, populating fields');
populateAllEventFields();
} else {
debugLog('Form not yet loaded, waiting more...');
// Try again after another delay
setTimeout(populateAllEventFields, 2000);
}
}, 2000);
}); });
/** /**
@ -612,7 +622,11 @@
$(window).on('load', function() { $(window).on('load', function() {
if (!populationAttempted) { if (!populationAttempted) {
debugLog('Window loaded, starting backup population attempt'); debugLog('Window loaded, starting backup population attempt');
setTimeout(populateAllEventFields, 500); setTimeout(function() {
if ($('#post_title, input[name="post_title"]').length > 0) {
populateAllEventFields();
}
}, 3000);
} }
}); });

View file

@ -132,6 +132,14 @@ class HVAC_Plugin {
// TEC Integration - Load early for proper routing // TEC Integration - Load early for proper routing
require_once HVAC_PLUGIN_DIR . 'includes/class-hvac-tec-integration.php'; require_once HVAC_PLUGIN_DIR . 'includes/class-hvac-tec-integration.php';
// Event Edit Fixes for TEC Community Events
if (file_exists(HVAC_PLUGIN_DIR . 'includes/class-hvac-event-edit-fix.php')) {
require_once HVAC_PLUGIN_DIR . 'includes/class-hvac-event-edit-fix.php';
}
if (file_exists(HVAC_PLUGIN_DIR . 'includes/class-hvac-event-edit-comprehensive.php')) {
require_once HVAC_PLUGIN_DIR . 'includes/class-hvac-event-edit-comprehensive.php';
}
// Feature includes - check if files exist before including // Feature includes - check if files exist before including
$feature_includes = [ $feature_includes = [
'class-hvac-trainer-status.php', 'class-hvac-trainer-status.php',
@ -487,13 +495,13 @@ class HVAC_Plugin {
new HVAC_Event_Summary(); new HVAC_Event_Summary();
} }
// DISABLED - Using TEC Community Events 5.x instead // Initialize event edit field population fixes
// if (class_exists('HVAC_Event_Edit_Fix')) { if (class_exists('HVAC_Event_Edit_Fix')) {
// HVAC_Event_Edit_Fix::instance(); HVAC_Event_Edit_Fix::instance();
// } }
// if (class_exists('HVAC_Event_Edit_Comprehensive')) { if (class_exists('HVAC_Event_Edit_Comprehensive')) {
// HVAC_Event_Edit_Comprehensive::instance(); HVAC_Event_Edit_Comprehensive::instance();
// } }
// Initialize trainer profile // Initialize trainer profile
if (class_exists('HVAC_Trainer_Profile')) { if (class_exists('HVAC_Trainer_Profile')) {

80
test-check-form-type.js Executable file
View file

@ -0,0 +1,80 @@
#!/usr/bin/env node
const { chromium } = require('@playwright/test');
(async () => {
console.log('Checking what form is actually on the manage event page...\n');
const browser = await chromium.launch({
headless: true,
args: ['--no-sandbox']
});
const page = await browser.newPage();
try {
// Login
console.log('1. Logging in...');
await page.goto('https://upskill-staging.measurequick.com/wp-login.php');
await page.fill('#user_login', 'test_admin');
await page.fill('#user_pass', 'TestAdmin2025!');
await page.click('#wp-submit');
await page.waitForTimeout(3000);
// Go to manage event page with event_id
console.log('2. Going to manage event page with event_id=6161...');
await page.goto('https://upskill-staging.measurequick.com/trainer/event/manage/?event_id=6161');
await page.waitForLoadState('networkidle');
// Check what's actually on the page
const pageContent = await page.evaluate(() => {
const results = {};
// Check for any forms
const forms = document.querySelectorAll('form');
results.formsCount = forms.length;
results.formIds = Array.from(forms).map(f => f.id || '(no id)');
// Check for TEC shortcode content
const shortcodeDiv = document.querySelector('[data-tribe-shortcode]');
results.hasTribeShortcode = !!shortcodeDiv;
// Check for actual TEC form
const tecForm = document.querySelector('#add-new-event, .tribe-community-events-content, #tribe-community-events');
results.hasTECForm = !!tecForm;
// Check page content
const contentArea = document.querySelector('.hvac-page-content');
if (contentArea) {
results.contentHTML = contentArea.innerHTML.substring(0, 2000);
}
// Check for title input specifically
const titleInput = document.querySelector('input[name="post_title"]');
results.hasTitleInput = !!titleInput;
results.titleValue = titleInput ? titleInput.value : null;
// Check for the shortcode itself
const shortcodeText = document.body.innerText.includes('[tribe_community_events]');
results.hasShortcodeText = shortcodeText;
return results;
});
console.log('\n3. Page Analysis:');
console.log(' Forms found:', pageContent.formsCount);
console.log(' Form IDs:', pageContent.formIds);
console.log(' Has TEC shortcode div:', pageContent.hasTribeShortcode);
console.log(' Has TEC form:', pageContent.hasTECForm);
console.log(' Has shortcode text:', pageContent.hasShortcodeText);
if (pageContent.contentHTML) {
console.log('\n4. Content preview:');
console.log(pageContent.contentHTML);
}
} catch (error) {
console.error('Error:', error.message);
} finally {
await browser.close();
}
})();

140
test-manage-event-form.js Executable file
View file

@ -0,0 +1,140 @@
#!/usr/bin/env node
const { chromium } = require('@playwright/test');
process.env.DISPLAY = ':0';
(async () => {
console.log('Testing manage event form population...\n');
const browser = await chromium.launch({
headless: true,
args: ['--no-sandbox']
});
const page = await browser.newPage();
try {
// Login
console.log('1. Logging in...');
await page.goto('https://upskill-staging.measurequick.com/wp-login.php');
await page.fill('#user_login', 'test_admin');
await page.fill('#user_pass', 'TestAdmin2025!');
await page.click('#wp-submit');
await page.waitForTimeout(3000);
// Go to manage event page with event_id
console.log('2. Going to manage event page with event_id=6161...');
await page.goto('https://upskill-staging.measurequick.com/trainer/event/manage/?event_id=6161');
await page.waitForLoadState('networkidle');
// Check if hvac_event_comprehensive object exists
const hasComprehensiveData = await page.evaluate(() => {
return typeof hvac_event_comprehensive !== 'undefined';
});
console.log('\n3. Checking for comprehensive data object:');
console.log(' Has hvac_event_comprehensive:', hasComprehensiveData);
if (hasComprehensiveData) {
const eventData = await page.evaluate(() => hvac_event_comprehensive);
console.log('\n4. Event data structure:');
console.log(' Event ID:', eventData.event_id);
console.log(' Has event_data:', !!eventData.event_data);
if (eventData.event_data) {
console.log(' Core data:', eventData.event_data.core);
console.log(' Venue data:', eventData.event_data.venue);
console.log(' Organizer data:', eventData.event_data.organizer);
}
}
// Check actual form fields
console.log('\n5. Checking form fields:');
const fields = await page.evaluate(() => {
const results = {};
// Try multiple selectors for title
const titleSelectors = [
'#title',
'input[name="post_title"]',
'#event-title',
'input[name="EventTitle"]'
];
for (const selector of titleSelectors) {
const field = document.querySelector(selector);
if (field) {
results.title = {
found: true,
selector: selector,
value: field.value
};
break;
}
}
if (!results.title) {
results.title = { found: false };
}
// Try multiple selectors for description
const descSelectors = [
'#description',
'textarea[name="post_content"]',
'#event-description',
'textarea[name="EventDescription"]'
];
for (const selector of descSelectors) {
const field = document.querySelector(selector);
if (field) {
results.description = {
found: true,
selector: selector,
value: field.value
};
break;
}
}
if (!results.description) {
results.description = { found: false };
}
// Check for TEC shortcode
const shortcodeDiv = document.querySelector('[data-tribe-shortcode]');
results.hasTECShortcode = !!shortcodeDiv;
// Check for any tribe forms
const tribeForms = document.querySelectorAll('form[id*="tribe"], form[class*="tribe"]');
results.tribeForms = tribeForms.length;
return results;
});
console.log(' Title field:', fields.title);
console.log(' Description field:', fields.description);
console.log(' Has TEC shortcode:', fields.hasTECShortcode);
console.log(' Tribe forms found:', fields.tribeForms);
// Check if the comprehensive JS ran
console.log('\n6. Checking if population script ran:');
const populationStatus = await page.evaluate(() => {
// Check if there's any indication the script tried to run
const notifications = document.querySelectorAll('.hvac-field-notification');
return {
notifications: notifications.length,
consoleErrors: window.hvacErrors || []
};
});
console.log(' Field notifications:', populationStatus.notifications);
} catch (error) {
console.error('Error:', error.message);
} finally {
console.log('\nKeeping browser open for 10 seconds...');
await page.waitForTimeout(10000);
await browser.close();
}
})();