Skip to content

Reload credential/provider edit forms via loadUrl() AJAX callback - #5

Merged
TheWitness merged 2 commits into
mainfrom
fix/edit-form-ajax-callback
Oct 16, 2026
Merged

TheWitness merged 2 commits into
mainfrom
fix/edit-form-ajax-callback

Conversation

@TheWitness

Copy link
Copy Markdown
Member

Summary

When editing a Secret Provider (credential_providers.php), changing the Provider Type reloaded the form with a full page navigation (document.location) instead of an AJAX callback, and after that first reload the dropdown stopped triggering the reload. The Credentials edit form (credentials.php / credentials.js) had the identical pattern on its Credential Type and Secret Provider dropdowns.

Root cause: the edit form first arrives as a Cacti AJAX #main fragment (handlers bind correctly), but document.location then does a full page navigation, where the inline init script runs at a different point relative to select2 setup, so the rebind never takes effect. Result: works once, dead after the first refresh.

Changes

  • credential_providers.php — reloadForType() now uses loadUrl({ url, force: true }) instead of document.location; the type dropdown keeps its direct, per-fragment rebind so every reload is a consistent AJAX fragment load.
  • credentials.js — same fix for both the Credential Type and Secret Provider dropdown reloads.
  • Migrated the remaining deprecated loadPageNoHeader() list-filter calls in credential_providers.php and credentials.php to loadUrl() (loadPageNoHeader now just logs a deprecation warning and wraps loadUrl).
  • force: true preserves the previous immediate-reload behavior and avoids a redundant unsaved-changes prompt on top of the existing "discard type config?" confirmation.
  • CHANGELOG entry added.

Notes

  • No __() strings were added or changed, so locales/po/cacti.pot is untouched.
  • php -l passes for both PHP files; node --check passes for credentials.js.

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

Changing the Provider Type (Secret Providers) or the Credential Type / Secret Provider (Credentials) performed a full page navigation via document.location and stopped triggering after the first refresh because subsequent loads went through a different init path than the initial AJAX fragment load.

Switch all type/provider dropdown reloads to the Cacti loadUrl() AJAX callback (force past the unsaved-changes check, as the switch intentionally rebuilds the form) so every reload is a consistent #main fragment load and the inline init re-binds each time. Also migrate the remaining deprecated loadPageNoHeader() filter calls to loadUrl().

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 16, 2026 01:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Supported Cacti 1.2.29 lacks loadUrl(), so the migrated calls need compatibility fallbacks.

1 open finding
What changed in this PR

Updates the Cacti credentials plugin to reload edit forms through AJAX, aiming to keep dropdown handlers working after repeated changes.

Changes:

  • Replaces full-page edit reloads with forced loadUrl() calls.
  • Migrates list-filter loading to loadUrl().
  • Documents the behavior change.
File Description
credentials.php Migrates credential list filters to loadUrl().
credentials.js Uses AJAX for credential type and provider switches.
credential_providers.php Updates provider type reloads and list filters.
CHANGELOG Records the dropdown reload fix.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread credentials.js Outdated
The plugin's INFO declares a compat floor of Cacti 1.2.29, whose include/layout.js defines loadPageNoHeader() but not loadUrl(). The prior commit's direct loadUrl() calls would throw ReferenceError there, leaving edit-form dropdowns and list filters dead.

Add a shared credentialsLoadUrl(url, force) helper that uses loadUrl() when present and otherwise falls back to loadPageNoHeader(url + '&header=false', false, force) to request a forced AJAX fragment. Define it as a guarded global in credentials.js and via a new credentials_loadurl_js() PHP emitter inlined into each page's scripts, so it is available even when reached through AJAX navigation where credentials.js is not reloaded.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sonarqubecloud

Copy link
Copy Markdown

@TheWitness
TheWitness merged commit 47b86fb into main Oct 16, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants