Skip to content

Commit

Permalink
Neo equivalent to craftcms/cms#12983
Browse files Browse the repository at this point in the history
  • Loading branch information
ttempleton committed Jun 2, 2023
1 parent 11b21a0 commit 8a29f11
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixed
- Fixed a bug when validation errors occurred when editing an element that has more than one Neo field, where some blocks could have multiple add block buttons added
- Fixed a bug when merging live entry changes into a draft, where newly-created blocks could end up in the wrong places in the draft's block structure
- Fixed a bug where Neo fields would fail validation if they only contained automatically-added blocks (per the field's Min Blocks setting) and no changes were made to them

## 3.7.9 - 2023-05-18

Expand Down
10 changes: 10 additions & 0 deletions src/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,16 @@ protected function inputHtml(mixed $value, ?ElementInterface $element = null): s
$block->useMemoized($value);
}

// Explanation: https://github.com/craftcms/cms/blob/4.4.13/src/fields/Matrix.php#L732-L735
if (
$this->minBlocks != 0 &&
count($filteredBlockTypes) === 1 &&
(!$element || !$element->hasErrors($this->handle)) &&
count($value) < $this->minBlocks
) {
$view->setInitialDeltaValue($this->handle, null);
}

return $view->renderTemplate('neo/input', [
'handle' => $this->handle,
'blocks' => $blocks,
Expand Down

0 comments on commit 8a29f11

Please sign in to comment.