Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

BUG Reload full view in admin/settings to avoid tabs breaking

Had the pjax "CurrentForm" marker set to the <form> tag,
which makes sense, but excludes the tabs. On refresh,
the tabset wasn't reinitialized, showing all form elements on
one page. Its easier to simply refresh the whole content area.
  • Loading branch information...
commit b74178e7fd2a0ba2b08cd11b41f0085b1dd4eee6 1 parent 54fd54a
@chillu chillu authored
View
14 code/controllers/CMSSettingsController.php
@@ -5,6 +5,15 @@ class CMSSettingsController extends LeftAndMain {
static $url_rule = '/$Action/$ID/$OtherID';
static $menu_priority = -1;
static $menu_title = 'Settings';
+
+ public function getResponseNegotiator() {
+ $neg = parent::getResponseNegotiator();
+ $controller = $this;
+ $neg->setCallback('CurrentForm', function() use(&$controller) {
+ return $controller->renderWith($controller->getTemplatesWithSuffix('_Content'));
+ });
+ return $neg;
+ }
/**
* @return Form
@@ -16,8 +25,8 @@ function getEditForm($id = null, $fields = null) {
$actions = $siteConfig->getCMSActions();
$form = new Form($this, 'EditForm', $fields, $actions);
$form->addExtraClass('root-form');
-
$form->addExtraClass('cms-edit-form cms-panel-padded center');
+ // don't add data-pjax-fragment=CurrentForm, its added in the content template instead
if($form->Fields()->hasTabset()) $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
$form->setHTMLID('Form_EditForm');
@@ -47,8 +56,7 @@ function save_siteconfig($data, $form) {
$siteConfig->write();
$this->response->addHeader('X-Status', rawurlencode(_t('LeftAndMain.SAVEDUP', 'Saved.')));
-
- return $form->forTemplate();
+ return $this->getResponseNegotiator()->respond($this->request);
}
function LinkPreview() {
View
2  templates/Includes/CMSSettingsController_Content.ss
@@ -1,4 +1,4 @@
-<div class="cms-content center cms-tabset $BaseCSSClasses" data-layout-type="border" data-pjax-fragment="Content">
+<div class="cms-content center cms-tabset $BaseCSSClasses" data-layout-type="border" data-pjax-fragment="Content CurrentForm">
<div class="cms-content-header north">
<% with EditForm %>

4 comments on commit b74178e

@patricknelson

@chillu Can you recall how to reproduce the bug that this commit was supposed to fix? The reason why I ask is because this diverges from the pjax convention of only reloading the form on error, which then completely prevents proper form validation if someone (like myself) intended to add that to the SiteConfig (in my case via DataExtension). See this bug that I think this commit created: #556

@chillu
Owner

@patricknelson Hmm, three years ago ;) It'd have been something around switching from one area to another, either from a ModelAdmin, admin/pages overview, or (most likely) and admin/pages/edit/show/<id> detail view. Shouldn't serverside form validation render both for full page and PJAX reloads thougH? Happy to review a pull request.

@patricknelson

Here you go! :D #1238

@patricknelson

I asked since I was trying to carefully investigate the basis here so I didn't break anything. Hopefully I didnt.

Please sign in to comment.
Something went wrong with that request. Please try again.