I am trying to add 2 repeaters to the page.
Everything works fine, but if the name of the second viewBag (viewBag [dogy]) starts with the name of the first (viewBag [dog]) we get the error "" Undefined offset: 0 "on line 398 of / srv / www / devv / modules / backend / formwidgets /Repeater.php ".
<?php namespace Pkurg\Reapeatertest;
use Cms\Classes\Theme;
use Event;
use System\Classes\PluginBase;
class Plugin extends PluginBase
{
public function boot()
{
//First repeater
Event::listen('backend.form.extendFields', function ($widget) {
if (!$widget->model instanceof \Cms\Classes\Page) {
return;
}
if (!($theme = Theme::getEditTheme())) {
throw new ApplicationException(Lang::get('cms::lang.theme.edit.not_found'));
}
if (false === $widget->isNested) {
$widget->addTabFields([
'viewBag[dog]' => [
'label' => 'My Dogs',
'type' => 'repeater',
'tab' => 'First repeater',
'form' => [
'fields' => [
'name' => [
'label' => 'Name',
'type' => 'text',
],
'text' => [
'label' => 'Text',
'type' => 'text',
],
],
],
],
]);
}
});
//Second repeater
Event::listen('backend.form.extendFields', function ($widget) {
if (!$widget->model instanceof \Cms\Classes\Page) {
return;
}
if (!($theme = Theme::getEditTheme())) {
throw new ApplicationException(Lang::get('cms::lang.theme.edit.not_found'));
}
if (false === $widget->isNested) {
$widget->addTabFields([
'viewBag[dogy]' => [
'label' => 'My Dogs',
'type' => 'repeater',
'tab' => 'Second repeater',
'form' => [
'fields' => [
'name' => [
'label' => 'Name',
'type' => 'text',
],
'text' => [
'label' => 'Text',
'type' => 'text',
],
],
],
],
]);
}
});
}
}
If you change viewBag [dogy] to viewBag [ddogy], everything starts working fine again.
The error occurs here.
file - /modules/backend/formwidgets/Repeater.php
聽聽聽/ **
聽聽聽聽聽* Determines the repeater that has triggered an AJAX request to add an item.
聽聽聽聽聽*
聽聽聽聽聽* @return void
聽聽聽聽聽* /
聽聽聽聽protected function checkAddItemRequest ()
聽聽聽聽{
聽聽聽聽聽聽聽聽$ handler = $ this-> getParentForm ()
聽聽聽聽聽聽聽聽聽聽聽聽-> getController ()
聽聽聽聽聽聽聽聽聽聽聽聽-> getAjaxHandler ();
聽聽聽聽聽聽聽聽if ($ handler === null || strpos ($ handler, '::') === false) {
聽聽聽聽聽聽聽聽聽聽聽聽return
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽list ($ widgetName, $ handlerName) = explode ('::', $ handler);
聽聽聽聽聽聽聽聽if ($ handlerName! == 'onAddItem') {
聽聽聽聽聽聽聽聽聽聽聽聽return
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽if ($ this-> alias === $ widgetName) {
聽聽聽聽聽聽聽聽聽聽聽聽// This repeater has made the AJAX request
聽聽聽聽聽聽聽聽聽聽聽聽self :: $ onAddItemCalled = true;
聽聽聽聽聽聽聽聽} else if (strpos ($ widgetName, $ this-> alias) === 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;
HERE-> $ this-> childIndexCalled = (int) $ matches [0];
聽聽聽聽聽聽聽聽}
聽聽聽聽}
Screencast -> https://www.youtube.com/watch?v=WrI9OSLTcLo
@pkurg Thanks for the report. Confirmed bug. I believe build 460 is now locked, so the fix for this will need to be done in 461.
@pkurg Would you mind testing the fix in #4814 and let us know if that resolves the issue for you?
@bennothommo you could launch an octodock instance with this PR for testing, I think this should be used for all PRs since it puts everyone on the same environment/libraries for testing.
What do you think?
@mjauvin I believe @LukeTowers has discussed that with @petehalverson as a possible thing to do down the track, but for the moment, I've only been posting links to it very sparingly (generally via DM) as there's no control over what someone may get up to with the instance if it's made public.
@pkurg Would you mind testing the fix in #4814 and let us know if that resolves the issue for you?
Yes, it solves the problem.
Most helpful comment
Yes, it solves the problem.