Error with yaml - Multiple Select form inside List form

Hi everyone!

Need some help with a grav error. I’m working on a gym website and I would like to create the classes schedule with 7 tabs (one for each day). In every tab there will be the classes of the selected day.

Example

Monday: yoga, pilates
Tuesday: pilates, box, karate
and so on…

So I created a class.yaml file with a list in order to add as many classes as I want. Inside the list, a Select form with Multiple enabled.

class.yaml file

header.classes:

          type: list
          label: Add Class
          fields:

            .title:
              type: text
              label: Name of the single class
            .days:
              type: select
              classes: fancy
              label: Days of classes
              multiple: true
              options:
                monday: Monday
                tuesday: Tuesday
                wednesday: Wednesday
                thursday: Thursday
                friday: Friday
                saturday: Saturday
                sunday: sunday

On back end it shows up good, but when I’m going to save something in this form I got this error “Array to string conversion”

Error Detail
    if ((!isset($params['multiline']) || !$params['multiline']) && preg_match('/\R/um', $value)) {
        return false;
    }

    return true;
}

protected static function filterText($value, array $params, array $field)
{
    return (string) $value;
}

protected static function filterCommaList($value, array $params, array $field)
{
    return is_array($value) ? $value : preg_split('/\s*,\s*/', $value, -1, PREG_SPLIT_NO_EMPTY);
}

protected static function typeCommaList($value, array $params, array $field)
{
    return is_array($value) ? true : self::typeText($value, $params, $field);
}

protected static function filterLower($value, array $params)
{

Am I doing something wrong? How can I prevent this to happen?
Thanks for the help!

try add validate commalist or array

  validate:
         type: commalist

or

validate:
          type: array
1 Like

Awesome! Adding validate: type: array worked, thanks dimitrilogo :wink:

If I can, I would like to ask another thing about this. I want to generate the content of these tabs automatically.
Basically I’m trying to make every class with the content of the array .days to be posted inside the correct tab.

Example
I create a new item in the list form with Title: Yoga Class and Days: Monday, Friday. So I want that this Yoga Class is going to be posted in both tabs Monday and Friday. This using the yaml file I posted above.

Twig
                            <div id="classes_monday" class="tab">
                                    {% for item in header.classes %}
                                        {% if item.days == 'monday' %}
                                        <ul>
                                            <li>{{ item.title }}</li>
                                            <li>{{ item.days }}</li>
                                        </ul>
                                        {% endif %}
                                    {% endfor %}
                            </div>

EDIT:

ok I found it, If someone need to do the same I used {% if '‘monday’ in item.days %}

Code
                            <div id="classes_monday" class="tab">
                                    {% for item in header.classes %}
                                        {% if ''monday' in item.days %}
                                        <ul>
                                            <li>{{ item.title }}</li>
                                            <li>{{ item.days }}</li>
                                        </ul>
                                        {% endif %}
                                    {% endfor %}
                            </div>

Thanks again dimitrilogo for your help!