Jump to content

problem by create repeaterfield in repeaterfield (warning message Undefined array key 'fields_id'" in ...\wire\core\WireSaveableItemsLookup.php:115)


Migu
 Share

Recommended Posts

Hello,

As soon as I try to add a RepeaterField inside another RepeaterField, I receive the warning message:

"Undefined array key 'fields_id'" in ...\wire\core\WireSaveableItemsLookup.php:115.

After refreshing the page, the message disappears.

However, when I add a text field to a RepeaterField, I do not encounter this issue.

Below, you can see the function I am using.

Can anyone tell me what I am doing wrong?

Thanks!

Miguel

 

    protected function createRepeaterField($repeaterName, $repeaterFields, $repeaterLabel , $repeaterTags='') {
        
        // Create Field
        $f = new Field();
        $f->type = wire('modules')->get("FieldtypeRepeater");
        $f->name = $repeaterName;
        $f->label = $repeaterLabel;
        $f->tags = $repeaterTags;         
        $f->save();

        //Create fieldgroup
        $repeaterFg = new Fieldgroup();
        $repeaterFg->name = "repeater_$repeaterName";
        $repeaterFg->save(); // Erst speichern!
        
        //Add fields to fieldgroup
        foreach($repeaterFields as $field) {      
            $repeaterFg->append(wire('fields')->get($field));
        }        
        $repeaterFg->save();
        

        //Create template
        $repeaterT = new Template();
        $repeaterT->name = "repeater_$repeaterName";
        $repeaterT->fieldgroup = $repeaterFg;
        
        $repeaterT->save();
    
        //Setup page for the repeater
            
        $repeaterPage = "for-field-{$f->id}";
        $f->parent_id = wire('pages')->get("name=$repeaterPage")->id;
        $f->template_id = $repeaterT->id;
        //Now, add the fields directly to the repeater field
        foreach($repeaterFields as $field) {
          $repeaterFieldIds[] = wire('fields')->get($field)->id;
        }

        $f->repeaterFields = $repeaterFieldIds;        
        $f->save();        
        return $f;
    }

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...