From b3fe2b5c630c56c1a77acad4defc378d97d5b7de Mon Sep 17 00:00:00 2001 From: madmatt Date: Thu, 5 Dec 2019 11:31:22 +1300 Subject: [PATCH] FIX: Fields with no modifier set fail to re-populate after a save, due to new implementation of Form::loadDataFrom() --- code/DateSelectorField.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/code/DateSelectorField.php b/code/DateSelectorField.php index 1c704fe..5cbc431 100644 --- a/code/DateSelectorField.php +++ b/code/DateSelectorField.php @@ -23,10 +23,15 @@ class DateSelectorField extends CompositeField { protected $year; public function __construct($name, $title = null, $value = null, $modifier = null) { - $this->name = $name .'[' . $modifier . ']'; + // Only set a modifier if one is provided + if ($modifier) { + $name = $name .'[' . $modifier . ']'; + $this->modifier = $modifier; + } + $this->name = $name; $this->setTitle($title); - $this->modifier = $modifier; + $dayArray = array( 0 => 'Day' ); @@ -93,6 +98,7 @@ public function __construct($name, $title = null, $value = null, $modifier = nul Requirements::css('dnadesign/silverstripe-datedropdownselectorfield: css/admin.css'); parent::__construct($fields); + $this->setName($name); $this->setValue($value); } @@ -104,10 +110,16 @@ public function setUseHeading($bool) { * Set the field name */ public function setName($name) { - $this->name = $name . '[' . $this->modifier . ']'; + if ($this->modifier) { + $this->name = $name . '[' . $this->modifier . ']'; + } else { + $this->name = $name; + } + $this->day->setName($this->name . '[Day]'); $this->month->setName($this->name . '[Month]'); $this->year->setName($this->name . '[Year]'); + return $this; }