Repository navigation
Reload credential/provider edit forms via loadUrl() AJAX callback - #5
Merged
Merged
Conversation
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>
There was a problem hiding this comment.
🟡 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.
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>
|
xmacan
approved these changes
Oct 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




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
#mainfragment (handlers bind correctly), butdocument.locationthen 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 usesloadUrl({ url, force: true })instead ofdocument.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.loadPageNoHeader()list-filter calls incredential_providers.phpandcredentials.phptoloadUrl()(loadPageNoHeadernow just logs a deprecation warning and wrapsloadUrl).force: truepreserves the previous immediate-reload behavior and avoids a redundant unsaved-changes prompt on top of the existing "discard type config?" confirmation.CHANGELOGentry added.Notes
__()strings were added or changed, solocales/po/cacti.potis untouched.php -lpasses for both PHP files;node --checkpasses forcredentials.js.Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com