Handle child FormWidgets making AJAX requests outside of the repeater's form container. Note that this won't pass on the state of the repeater item as it exists on the webpage because that information won't be sent to the server in an AJAX request sent from outside of the repeater's form container unless the FormWidget sending the orphaned request specifically includes that data in their request, in which case the regular handling will kick in and initialize the widget properly. A discussion should be had whether this fix makes sense to be done in the Repeater FormWidget or if we should force FormWidgets to have the responsibility of initializing their parent repeaters if they're going to be making orphaned AJAX requests. Should fix #3415, #4672. Related: octoberrain/test-plugin#78
This commit is contained in:
parent
b2dcd3c9fd
commit
96e335aebc
|
|
@ -220,6 +220,21 @@ class Repeater extends FormWidgetBase
|
||||||
? post($this->formField->getName())
|
? post($this->formField->getName())
|
||||||
: $this->getLoadValue();
|
: $this->getLoadValue();
|
||||||
|
|
||||||
|
// Detect when a child widget is trying to run an AJAX handler
|
||||||
|
// outside of the form element that contains all the repeater
|
||||||
|
// fields that would normally be used to identify that case
|
||||||
|
$handler = $this->controller->getAjaxHandler();
|
||||||
|
if (!$this->loaded && starts_with($handler, $this->alias . 'Form')) {
|
||||||
|
// Attempt to get the index of the repeater
|
||||||
|
$handler = str_after($handler, $this->alias . 'Form');
|
||||||
|
preg_match("~^(\d+)~", $handler, $matches);
|
||||||
|
|
||||||
|
if (isset($matches[1])) {
|
||||||
|
$index = $matches[1];
|
||||||
|
$this->makeItemFormWidget($index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!$this->childAddItemCalled && $currentValue === null) {
|
if (!$this->childAddItemCalled && $currentValue === null) {
|
||||||
$this->formWidgets = [];
|
$this->formWidgets = [];
|
||||||
return;
|
return;
|
||||||
|
|
@ -269,7 +284,7 @@ class Repeater extends FormWidgetBase
|
||||||
$config = $this->makeConfig($configDefinition);
|
$config = $this->makeConfig($configDefinition);
|
||||||
$config->model = $this->model;
|
$config->model = $this->model;
|
||||||
$config->data = $this->getValueFromIndex($index);
|
$config->data = $this->getValueFromIndex($index);
|
||||||
$config->alias = $this->alias . 'Form'.$index;
|
$config->alias = $this->alias . 'Form' . $index;
|
||||||
$config->arrayName = $this->getFieldName().'['.$index.']';
|
$config->arrayName = $this->getFieldName().'['.$index.']';
|
||||||
$config->isNested = true;
|
$config->isNested = true;
|
||||||
if (self::$onAddItemCalled || $this->minItems > 0) {
|
if (self::$onAddItemCalled || $this->minItems > 0) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue