More strict checking of addItem request for child repeaters (#4814)

Similarly named repeater fields being used in viewBag variables were being assigned aliases which succeeded the `strpos` check on line 407. This will more clearly look for a child repeater form and index.

Fixes #4808
This commit is contained in:
Ben Thomson 2019-12-12 18:44:10 +08:00 committed by Samuel Georges
parent 5839b6869a
commit c17cb58aa1

View File

@ -98,7 +98,7 @@ class Repeater extends FormWidgetBase
public function init()
{
$this->prompt = Lang::get('backend::lang.repeater.add_new_item');
$this->fillFromConfig([
'form',
'prompt',
@ -404,15 +404,15 @@ class Repeater extends FormWidgetBase
if ($this->alias === $widgetName) {
// This repeater has made the AJAX request
self::$onAddItemCalled = true;
} else if (strpos($widgetName, $this->alias) === 0) {
} else if (strpos($widgetName, $this->alias . 'Form') === 0) {
// A child repeater has made the AJAX request
// Get index from AJAX handler
$handlerSuffix = str_replace($this->alias . 'Form', '', $widgetName);
preg_match('/^[0-9]+/', $handlerSuffix, $matches);
$this->childAddItemCalled = true;
$this->childIndexCalled = (int) $matches[0];
if (preg_match('/^[0-9]+/', $handlerSuffix, $matches)) {
$this->childAddItemCalled = true;
$this->childIndexCalled = (int) $matches[0];
}
}
}