This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

code200.miha
code200.miha

How to set default values for repeater field in settings?

Thanks!

Mohsin
Mohsin

In your form field yaml file under repeater use the default attribute as follows

characters:
    label: Characters
    type: repeater
    default:
        0:
            name: Jim Moriarty
            phone: 1234554321
        1:
            name: Irene Adler
            is_enabled: 1234554321
    form:
        fields:
            name:
              label: Name

            phone:
              label: Phone

This example is in the case where the fields are just name and phone. In your case, you will need to write the code based on your fields. This is basically an Array in the YAML language and it gets converted to json when it stores in the database. If you use complex configs like groups in the repeater config then the group meta too must be passed in this array. Best idea is to make a repeater without the default, add all the values you need as default. Now open your database and in the repeater field get the json, convert that to the YAML array format and paste in under default. That will work best.

Last updated

Troiscent
Troiscent

When I try your syntax, I got the following error :

substr() expects parameter 1 to be string, array given" on line 469 of 
/vendor/laravel/framework/src/Illuminate/Support/Str.php

Here is my syntax for that field :

    forms:
        label: Forms
        type: repeater
        span: full
        tab: Infos
        form:
            fields:
                url:
                    label: Url
                    span: auto
                lifetime: 
                    label: Lifetime
                    span: auto
                description:
                    label: Description
                    span: full
        default:
            0:
                url: /contact
                lifetime: "3 mois après l'envoi"
                description: "Demande de renseignement par l'internaute"
alex30517
alex30517

is work for me:

forms:
    label: Forms
    type: repeater
    span: full
    tab: Infos
    form:
        fields:
            url:
                label: Url
                span: auto
            lifetime: 
                label: Lifetime
                span: auto
            description:
                label: Description
                span: full
    default: '[{"url":"/contact","lifetime":"3 mois après l'envoi","description":"Demande de renseignement par l'internaute"}]'

Last updated

1-4 of 4

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.