Finish implementing titleFrom option for Repeaters

Ref: e7609aa5e8
This commit is contained in:
Luke Towers 2018-08-11 20:27:53 -06:00
parent 4cdbf2a051
commit 6774920003
3 changed files with 10 additions and 2 deletions

View File

@ -31,6 +31,11 @@ class Repeater extends FormWidgetBase
*/
public $sortable = false;
/**
* @var string Field name to use for the title of collapsed items
*/
public $titleFrom = false;
/**
* @var int Maximum repeated items allowable.
*/
@ -88,6 +93,7 @@ class Repeater extends FormWidgetBase
'form',
'prompt',
'sortable',
'titleFrom',
'maxItems',
]);
@ -125,7 +131,7 @@ class Repeater extends FormWidgetBase
if (!self::$onAddItemCalled) {
$this->processExistingItems();
}
if ($this->previewMode) {
foreach ($this->formWidgets as $widget) {
$widget->previewMode = true;
@ -137,6 +143,7 @@ class Repeater extends FormWidgetBase
$this->vars['prompt'] = $this->prompt;
$this->vars['formWidgets'] = $this->formWidgets;
$this->vars['titleFrom'] = $this->titleFrom;
$this->vars['maxItems'] = $this->maxItems;
$this->vars['useGroups'] = $this->useGroups;

View File

@ -181,7 +181,7 @@
}
if (this.options.titleFrom) {
$target = $('[data-field-name="'+this.options.titleFrom+'"]')
$target = $('[data-field-name="'+this.options.titleFrom+'"]', $item)
if (!$target.length) {
$target = $item
}

View File

@ -1,5 +1,6 @@
<div class="field-repeater"
data-control="fieldrepeater"
<?= $titleFrom ? 'data-title-from="'.$titleFrom.'"' : '' ?>
<?= $maxItems ? 'data-max-items="'.$maxItems.'"' : '' ?>
data-sortable-container="#<?= $this->getId('items') ?>"
data-sortable-handle=".<?= $this->getId('items') ?>-handle">