Skip to content

Commit

Permalink
Merge pull request #15 from madmatt/pulls/fix-ss4-nomodifier
Browse files Browse the repository at this point in the history
FIX: Fields with no modifier set fail to re-populate after a save
  • Loading branch information
wilr authored Dec 5, 2019
2 parents 3372dd5 + b3fe2b5 commit 62b1a25
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions code/DateSelectorField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
Expand Down Expand Up @@ -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);
}

Expand All @@ -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;
}

Expand Down

0 comments on commit 62b1a25

Please sign in to comment.