From c5d538c3660268082c656fc708bd94d5fb272570 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 12 Mar 2008 08:54:24 +0000 Subject: [PATCH] Merged revisions 50947 via svnmerge from svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.2.2 ........ r50947 | ischommer | 2008-03-12 21:53:28 +1300 (Wed, 12 Mar 2008) | 1 line BUGFIX properly setting $childID in form for newly created items to avoid duplicates after subsequent saving (the form reloaded without the ID connection) ........ git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@50941 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- forms/ComplexTableField.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/forms/ComplexTableField.php b/forms/ComplexTableField.php index 0cdf312ac..4b19bae1e 100755 --- a/forms/ComplexTableField.php +++ b/forms/ComplexTableField.php @@ -253,12 +253,14 @@ JS; * , Link back to the correct parent record (e.g. "parentID"). * parentClass, Link back to correct container-class (the parent-record might have many 'has-one'-relationships) * CAUTION: "ID" in the DetailForm would be the "childID" in the overview table. + * + * @param int $childID */ - function DetailForm() { + function DetailForm($childID = null) { // Get all the requests $ID = isset($_REQUEST['ctf']['ID']) ? Convert::raw2xml($_REQUEST['ctf']['ID']) : null; - $childID = isset($_REQUEST['ctf']['childID']) ? Convert::raw2xml($_REQUEST['ctf']['childID']) : null; + if(!isset($childID)) $childID = isset($_REQUEST['ctf']['childID']) ? Convert::raw2xml($_REQUEST['ctf']['childID']) : null; $childClass = Convert::raw2xml($_REQUEST['fieldName']); $this->methodName = isset($_REQUEST['methodName']) ? $_REQUEST['methodName'] : null; @@ -766,9 +768,10 @@ class ComplexTableField_Popup extends Form { $this->saveInto($childObject); $childObject->write(); + // if ajax-call in an iframe, update window if(Director::is_ajax()) { - // if ajax-call in an iframe, update window - $form = $this->controller->DetailForm(); + // Newly saved objects need their ID reflected in the reloaded form to avoid double saving + $form = $this->controller->DetailForm($childObject->ID); $form->loadDataFrom($childObject); FormResponse::update_dom_id($form->FormName(), $form->formHtmlContent(), true, 'update'); return FormResponse::respond();