mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
Peer review #2723
This commit is contained in:
parent
fedf7b2b7d
commit
e9cc782120
@ -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}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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">
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user