This commit is contained in:
Samuel Georges 2017-03-01 14:31:37 +11:00
parent fedf7b2b7d
commit e9cc782120
3 changed files with 10 additions and 13 deletions

View File

@ -52,11 +52,11 @@ class Repeater extends FormWidgetBase
* @var bool Stops nested repeaters populating from previous sibling.
*/
protected static $onAddItemCalled = false;
/**
* @var int Maximum repeated items (0 == unlimited items)
* @var int Maximum repeated items allowable.
*/
protected $maxItems = 0;
protected $maxItems = null;
/**
* {@inheritDoc}

View File

@ -45,7 +45,7 @@
this.$el.on('click', '> ul > li > .repeater-item-collapse .repeater-item-collapse-one', this.proxy(this.toggleCollapse))
this.$el.one('dispose-control', this.proxy(this.dispose))
this.togglePrompt()
}
@ -79,7 +79,7 @@
this.$sortable.sortable(sortableOptions)
}
Repeater.prototype.onRemoveItemSuccess = function(ev) {
$(ev.target).closest('.field-repeater-item').remove()
this.togglePrompt()
@ -88,17 +88,13 @@
Repeater.prototype.onAddItemSuccess = function(ev) {
this.togglePrompt()
}
Repeater.prototype.togglePrompt = function () {
if (this.options.maxItems != 0) {
if (this.options.maxItems && this.options.maxItems > 0) {
var repeatedItems = this.$el.find('> .field-repeater-items > .field-repeater-item').length,
$addItemBtn = this.$el.find('> .field-repeater-add-item')
if (repeatedItems >= this.options.maxItems) {
$addItemBtn.hide()
} else if (repeatedItems < this.options.maxItems) {
$addItemBtn.show()
}
$addItemBtn.toggle(repeatedItems < this.options.maxItems)
}
}

View File

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