Fixes issue with index incrementation

This commit is contained in:
Samuel Georges 2017-04-22 21:40:35 +10:00
parent 46fcdbc636
commit 83e80745b3
4 changed files with 22 additions and 13 deletions

View File

@ -92,8 +92,8 @@ class Repeater extends FormWidgetBase
]);
$fieldName = $this->formField->getName(false);
$this->indexInputName = self::INDEX_PREFIX.$fieldName.'[]';
$this->groupInputName = self::GROUP_PREFIX.$fieldName.'[]';
$this->indexInputName = self::INDEX_PREFIX.$fieldName;
$this->groupInputName = self::GROUP_PREFIX.$fieldName;
$this->processGroupMode();
@ -166,15 +166,15 @@ class Repeater extends FormWidgetBase
$itemIndexes = post($this->indexInputName, $loadValue);
$itemGroups = post($this->groupInputName, $loadValue);
if (!count($itemIndexes)) {
return;
}
$items = array_combine(
(array) $itemIndexes,
(array) ($this->useGroups ? $itemGroups : $itemIndexes)
);
if (!is_array($items)) {
return;
}
foreach ($items as $itemIndex => $groupCode) {
$this->makeItemFormWidget($itemIndex, $groupCode);
$this->indexCount = max((int) $itemIndex, $this->indexCount);
@ -225,8 +225,6 @@ class Repeater extends FormWidgetBase
$this->indexCount++;
traceLog($this->indexCount);
$groupCode = post('_repeater_group');
$this->prepareVars();

View File

@ -83,11 +83,23 @@
}
Repeater.prototype.clickAddGroupButton = function(ev) {
var templateHtml = $('> [data-group-palette-template]', this.$el).html()
var templateHtml = $('> [data-group-palette-template]', this.$el).html(),
$target = $(ev.target),
$form = this.$el.closest('form')
$(ev.target).ocPopover({
$target.ocPopover({
content: templateHtml
})
var $container = $target.data('oc.popover').$container
$container.on('click', 'a', function (ev) {
setTimeout(function() {
$(ev.target).trigger('close.oc.popover')
}, 1)
})
$('[data-repeater-add]', $container).data('request-form', $form)
}
Repeater.prototype.onRemoveItemSuccess = function(ev) {

View File

@ -49,7 +49,6 @@
<li>
<a
href="javascript:;"
onclick="$(this).trigger('close.oc.popover')"
data-repeater-add
data-request="<?= $this->getEventHandler('onAddItem') ?>"
data-request-data="_repeater_group: '<?= $item['code'] ?>'">

View File

@ -37,9 +37,9 @@
<?php endforeach ?>
</div>
<input type="hidden" name="<?= $indexInputName ?>" value="<?= $indexValue ?>" />
<input type="hidden" name="<?= $indexInputName ?>[]" value="<?= $indexValue ?>" />
<?php if ($useGroups): ?>
<input type="hidden" name="<?= $groupInputName ?>" value="<?= $groupCode ?>" />
<input type="hidden" name="<?= $groupInputName ?>[]" value="<?= $groupCode ?>" />
<?php endif ?>
</li>