Add callback for handling sorted repeater items
This commit is contained in:
parent
98832fbc57
commit
f49b5ab4b8
|
|
@ -322,6 +322,11 @@ class Repeater extends FormWidgetBase
|
|||
return $widget->onRefresh();
|
||||
}
|
||||
|
||||
public function onReorder()
|
||||
{
|
||||
// Handle reordering of repeater items
|
||||
}
|
||||
|
||||
//
|
||||
// Group mode
|
||||
//
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@
|
|||
|
||||
Repeater.DEFAULTS = {
|
||||
sortableHandle: '.repeater-item-handle',
|
||||
sortableHandler: null,
|
||||
sortableContainer: 'ul.field-repeater-items',
|
||||
titleFrom: null,
|
||||
minItems: null,
|
||||
|
|
@ -232,13 +233,20 @@
|
|||
Repeater.prototype.onSortStart = function($item, container, callback, event) {
|
||||
this.sortingStartIndex = $item.index()
|
||||
|
||||
callback($item, container, callback, event);
|
||||
callback($item, container, callback, event)
|
||||
}
|
||||
|
||||
Repeater.prototype.onSortStop = function($item, container, callback, event) {
|
||||
var endIndex = $item.index()
|
||||
|
||||
callback($item, container, callback, event);
|
||||
this.$el.request(this.options.sortableHandler, {
|
||||
data: {
|
||||
_repeater_index: this.sortingStartIndex,
|
||||
_repeater_new_index: endIndex
|
||||
}
|
||||
})
|
||||
|
||||
callback($item, container, callback, event)
|
||||
}
|
||||
|
||||
// FIELD REPEATER PLUGIN DEFINITION
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
<?= $titleFrom ? 'data-title-from="'.$titleFrom.'"' : '' ?>
|
||||
<?= $minItems ? 'data-min-items="'.$minItems.'"' : '' ?>
|
||||
<?= $maxItems ? 'data-max-items="'.$maxItems.'"' : '' ?>
|
||||
data-sortable-handler="<?= $this->getEventHandler('onReorder') ?>"
|
||||
data-sortable-container="#<?= $this->getId('items') ?>"
|
||||
data-sortable-handle=".<?= $this->getId('items') ?>-handle">
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue