I have extended the fields of OctoberCms and I have added a repeater field but when I click "add new item" instead of adding one input box as I wanted to it adds all the fields I have created in general even fields of other tabs.
When I click "add new item" I wanted one input box to be created but it recreates all the fields that exist in the backend.
This is what happens after I click "add new itens":

But I want this to be created insted:

This is how I have extended the fields (Plugin.php):
public function boot()
{
Event::listen('backend.form.extendFields', function($widget)
{
if (!$widget->model instanceof \Cms\Classes\Page) return;
//cms page fields
$widget->addFields([
'settings[str_seo_title]' =>[
'label' => 'Meta Title',
'tab' => 'SEO',
'type' => 'text'
],
'settings[str_seo_description]' =>[
'label' => 'Meta Description',
'tab' => 'SEO',
'size' => 'small',
'type' => 'textarea'
],
'settings[str_seo_keywords]' =>[
'label' => 'Meta Keywords',
'tab' => 'SEO',
'type' => 'text'
],
'settings[str_canonical_url]' => [
'label' => 'Canonical URL',
'type' => 'text',
'tab' => 'SEO',
],
'settings[str_robot_index]' => [
'label' => 'Robot Index',
'type' => 'dropdown',
'tab' => 'SEO',
'options' => ["index"=>"index","noindex"=>"noindex"],
'default' => 'index',
'span' => 'left'
],
'settings[str_robot_follow]' => [
'label' => 'Robot Follow',
'type' => 'dropdown',
'tab' => 'SEO',
'options' => ["follow"=>"follow","nofollow"=>"nofollow"],
'default' => 'follow',
'span' => 'right'
],
'settings[str_local_og_sitename]' => [
'label' => 'Site name',
'tab' => 'Open Graph',
'type' => 'text',
'placeholder' => 'Example: strong answer',
],
'settings[str_local_og_title]' => [
'label' => 'Title',
'type' => 'text',
'placeholder' => 'Example: New features',
'tab' => 'Open Graph',
],
'settings[str_local_og_description]' => [
'label' => 'Description',
'type' => 'textarea',
'size' => 'small',
'placeholder' => 'Example: seo plugin is a plugin that handles meta tags',
'tab' => 'Open Graph',
],
'settings[str_local_og_url]' => [
'label' => 'Page url',
'placeholder' => 'Example: http://www.strong-answer.com/',
'type' => 'text',
'tab' => 'Open Graph',
],
'settings[str_local_og_type]' => [
'label' => 'Type',
'type' => 'text',
'placeholder' => 'Example: website',
'tab' => 'Open Graph',
],
'settings[str_local_og_author]' => [
'label' => 'Author',
'type' => 'text',
'placeholder' => 'Example: Strong Answer',
'tab' => 'Open Graph',
],
'settings[str_local_og_img]' => [
'label' => 'Image path',
'type' => 'text',
'placeholder' => 'http://october.com/storage/app/media/Koala.jpg',
'tab' => 'Open Graph',
],
'settings[str_local_og_gl_title]' => [
'label' => 'Name for the post',
'type' => 'text',
'placeholder' => 'Example: My post title',
'tab' => 'Google Tags',
],
'settings[str_local_og_gl_description]' => [
'label' => 'The description of your post',
'type' => 'textarea',
'size' => 'small',
'placeholder' => 'Example: seo plugin is a plugin that handles meta tags',
'tab' => 'Google Tags',
],
'settings[str_local_og_gl_img]' => [
'label' => 'The image of your post',
'type' => 'text',
'placeholder' => 'Example: http://october.com/storage/app/media/Koala.jpg',
'tab' => 'Google Tags',
],
'settings[str_local_og_gl_page]' => [
'label' => 'Business page link',
'type' => 'text',
'placeholder' => 'Example: www.epicsite.com',
'tab' => 'Google Tags',
],
'settings[str_local_og_tt_card]' => [
'label' => 'Summary of your card',
'type' => 'textarea',
'size' => 'small',
'placeholder' => 'Example: Happy 3rd anniversary #TBT!',
'tab' => 'Twitter Tags',
],
'settings[str_local_og_tt_site]' => [
'label' => 'Twitter user',
'type' => 'text',
'placeholder' => 'Example: @stronganswer',
'tab' => 'Twitter Tags',
],
'settings[str_local_og_tt_title]' => [
'label' => 'Twitter title',
'type' => 'text',
'placeholder' => 'Example: Small Island Developing States Photo Submission',
'tab' => 'Twitter Tags',
],
'settings[str_local_og_tt_description]' => [
'label' => 'Twitter description',
'type' => 'textarea',
'size' => 'small',
'placeholder' => 'Example: seo plugin is a plugin that handles meta tags',
'tab' => 'Twitter Tags',
],
'settings[str_local_og_tt_img]' => [
'label' => 'Twitter image',
'type' => 'text',
'placeholder' => 'Example: http://october.com/storage/app/media/Koala.jpg',
'tab' => 'Twitter Tags',
],
'settings[str_local_og_fb_appid]' => [
'label' => 'Facebook App Id',
'type' => 'text',
'placeholder' => 'Example: 302184056577324',
'tab' => 'Facebook Tags',
],
//this is the repeater field:
'settings[str_local_og_fb_admins]' => [
'label' => 'Facebook Admins',
'type' => 'repeater',
'tab' => 'Facebook Tags',
'form' => [
'fields' => [
'settings[str_local_og_fb_admins]' => [
'label' => 'Facebook Admin',
'type' => 'text'
]
]
]
]
], 'primary');
});
}
How do I make the output turn like the second image ?
(I have allready tried to change the name of the subfield of the repeater from settings[str_local_og_fb_admins] to only str_admins, and it still keeps repeating the other fields).
You need to bypass the event if it runs over the repeater Form widget. check with XDebug to understand what's going on.
For exemple add this test at the beginning of the closure (before ->addFields)
if (starts_with($widget->arrayName, "settings[str_local_og_fb_admins]")) {
return;
}
Tests the current form widget (being extended) property
arrayNameagainst the value to exclude. The form widget arrayName of the repeater starts with the repeater name
the repeater is now working fine.
but now I'm havin an exception "Class name is not registered for the component "str_local_og_fb_admins". Check the component plugin." when ever I try to enter the page.
ok I have open the page file where the data is saved and it's saved like this:
title = "Demonstration"
url = "/"
layout = "default"
is_hidden = 0
str_seo_title = "drdf"
str_seo_description = "hhh"
str_seo_keywords = "meta keywords"
str_canonical_url = "canonical url" <!--this are the other fields, they all work properly -->
str_robot_index = "noindex"
str_robot_follow = "nofollow"
str_local_og_more = "<meta name=\":d\" content=\":3\">
<meta name=\"more\" content=\"more\">"
[str_local_og_fb_admins] <!-- this is the repeater field -->
1[settings][str_local_og_fb_admin] = 0 <!--I have saved this value "0"-->
==
(...)
But it should be saving like this:
title = "Demonstration"
url = "/"
layout = "default"
is_hidden = 0
str_seo_title = "drdf"
str_seo_description = "hhh"
str_seo_keywords = "meta keywords"
str_canonical_url = "canonical url" <!--this are the other fields, they all work properly -->
str_robot_index = "noindex"
str_robot_follow = "nofollow"
str_local_og_more = "<meta name=\":d\" content=\":3\">
<meta name=\"more\" content=\"more\">"
str_local_og_fb_admins = 0 <!-- repeater field -->
==
(...)
This is the error that appears (click on it if you are having troubles reading it):

I don't think the CMS page where built with something like this in mind. A repeater will typically produce an array of something, but page properties are just key/value pairs of primitives (string/int/bool i think). You might have to do the transform yourself somewhere (I don't know if it's possible) to convert the repeaters values to a key/pair of primitives (serialize the repeater array, json, etc.).
thanks for the help I will try to find a way to get around this.
Hey, kraven2g! I'm dealing with the same problem with repeater. Can you share your solution? I still can't find a way to avoid other fields showing up in repeater. I tried to change names of fields n stuff but still nothing. Please help!
I'm sorry to tell you but I didn't find any, I think that is not possible to do it yet based on the search I have made.
@eeliinaaa @kraven2g is this now fixed by https://github.com/octobercms/october/issues/2257#issuecomment-258567160?
@LukeTowers can't tell I had to find another way to do it but that I know of there wasn't a fix.
Since #2257, you can wrap if (!$widget->isNested) { around your addFields and this will stop them appearing in repeater fields.
Most helpful comment
Since #2257, you can wrap
if (!$widget->isNested) {around your addFields and this will stop them appearing in repeater fields.