diff --git a/code/controllers/AssetAdmin.php b/code/controllers/AssetAdmin.php index 7f78b8067d..b5f600865a 100644 --- a/code/controllers/AssetAdmin.php +++ b/code/controllers/AssetAdmin.php @@ -417,7 +417,8 @@ public function SearchForm() { } public function AddForm() { - $form = CMSForm::create( + $negotiator = $this->getResponseNegotiator(); + $form = Form::create( $this, 'AddForm', new FieldList( @@ -430,7 +431,19 @@ public function AddForm() { ->setTitle(_t('AssetAdmin.ActionAdd', 'Add folder')) ) )->setHTMLID('Form_AddForm'); - $form->setResponseNegotiator($this->getResponseNegotiator()); + $form->setValidationResponseCallback(function() use ($negotiator, $form) { + $request = $this->getRequest(); + if($request->isAjax() && $negotiator) { + $form->setupFormErrors(); + $result = $form->forTemplate(); + + return $negotiator->respond($request, array( + 'CurrentForm' => function() use($result) { + return $result; + } + )); + } + }); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); // TODO Can't merge $FormAttributes in template at the moment $form->addExtraClass('add-form cms-add-form cms-edit-form cms-panel-padded center ' . $this->BaseCSSClasses()); diff --git a/code/controllers/CMSMain.php b/code/controllers/CMSMain.php index 2ea1341bcf..f47171397c 100644 --- a/code/controllers/CMSMain.php +++ b/code/controllers/CMSMain.php @@ -588,7 +588,7 @@ public function getRecord($id, $versionID = null) { /** * @param int $id * @param FieldList $fields - * @return CMSForm + * @return Form */ public function getEditForm($id = null, $fields = null) { if(!$id) $id = $this->currentPageID(); @@ -656,18 +656,8 @@ public function getEditForm($id = null, $fields = null) { $validator = new RequiredFields(); } - $form = CMSForm::create( - $this, "EditForm", $fields, $actions, $validator - )->setHTMLID('Form_EditForm'); - $form->setResponseNegotiator($this->getResponseNegotiator()); - $form->loadDataFrom($record); - $form->disableDefaultAction(); - $form->addExtraClass('cms-edit-form'); - $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); // TODO Can't merge $FormAttributes in template at the moment $form->addExtraClass('center ' . $this->BaseCSSClasses()); - // if($form->Fields()->hasTabset()) $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); - $form->setAttribute('data-pjax-fragment', 'CurrentForm'); // Set validation exemptions for specific actions $form->setValidationExemptActions(array('restore', 'revert', 'deletefromlive', 'delete', 'unpublish', 'rollback', 'doRollback')); @@ -684,10 +674,9 @@ public function getEditForm($id = null, $fields = null) { $this->extend('updateEditForm', $form); return $form; } else if($id) { - $form = CMSForm::create( $this, "EditForm", new FieldList( + $form = Form::create( $this, "EditForm", new FieldList( new LabelField('PageDoesntExistLabel',_t('CMSMain.PAGENOTEXISTS',"This page doesn't exist"))), new FieldList() )->setHTMLID('Form_EditForm'); - $form->setResponseNegotiator($this->getResponseNegotiator()); return $form; } } @@ -842,14 +831,27 @@ public function ListViewForm() { } )); - $listview = CMSForm::create( + $negotiator = $this->getResponseNegotiator(); + $listview = Form::create( $this, 'ListViewForm', new FieldList($gridField), new FieldList() )->setHTMLID('Form_ListViewForm'); $listview->setAttribute('data-pjax-fragment', 'ListViewForm'); - $listview->setResponseNegotiator($this->getResponseNegotiator()); + $listview->setValidationResponseCallback(function() use ($negotiator, $listview) { + $request = $this->getRequest(); + if($request->isAjax() && $negotiator) { + $listview->setupFormErrors(); + $result = $listview->forTemplate(); + + return $negotiator->respond($request, array( + 'CurrentForm' => function() use($result) { + return $result; + } + )); + } + }); $this->extend('updateListView', $listview); diff --git a/code/controllers/CMSPageAddController.php b/code/controllers/CMSPageAddController.php index 1beb6276e6..9a342ae084 100644 --- a/code/controllers/CMSPageAddController.php +++ b/code/controllers/CMSPageAddController.php @@ -113,14 +113,26 @@ public function AddForm() { ); $this->extend('updatePageOptions', $fields); - - $form = CMSForm::create( + + $negotiator = $this->getResponseNegotiator(); + $form = Form::create( $this, "AddForm", $fields, $actions )->setHTMLID('Form_AddForm'); $form->setAttribute('data-hints', $this->SiteTreeHints()); $form->setAttribute('data-childfilter', $this->Link('childfilter')); - - $form->setResponseNegotiator($this->getResponseNegotiator()); + $form->setValidationResponseCallback(function() use ($negotiator, $form) { + $request = $this->getRequest(); + if($request->isAjax() && $negotiator) { + $this->setupFormErrors(); + $result = $this->forTemplate(); + + return $negotiator->respond($request, array( + 'CurrentForm' => function() use($result) { + return $result; + } + )); + } + }); $form->addExtraClass('cms-add-form stacked cms-content center cms-edit-form ' . $this->BaseCSSClasses()); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); diff --git a/code/controllers/CMSPageHistoryController.php b/code/controllers/CMSPageHistoryController.php index 3503d1bd9c..7048765e0c 100644 --- a/code/controllers/CMSPageHistoryController.php +++ b/code/controllers/CMSPageHistoryController.php @@ -253,13 +253,13 @@ public function VersionsForm() { // Use