Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

how do I use data-options@ with a select_optgroup field?

Started by Anna 1 hour ago · 0 replies · 4 views
1 hour ago

I have a frontend form with one large select field with optgroups. These are the names of five parent pages and then underneath their child pages are listed as options. How do I pass this structure to data-options@ in the field’s definition?

I tried

PHP
$arrOptions = [
    'Optgroup 1' => [
        '1-1' => 'Group 1 Option 1',
        '1-2' => 'Group 1 Option 2',
        '1-3' => 'Group 1 Option 3',
    ],
    'Optgroup 2' => [
        '2-1' => 'Group 2 Option 1',
        '2-2' => 'Group 2 Option 2',
        '2-3' => 'Group 2 Option 3',
    ],
];
return $arrOptions;

but that just gets output as <optgroup label="1-1"></optgroup><optgroup label="2-1"></optgroup>.

Is it even doable? If so, how?

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Anna, 23 hours ago
5 44 1 hour ago
Forms & Blueprints · by Anna, 1 week ago
5 170 4 days ago
Forms & Blueprints · by TomW, 1 month ago
3 366 1 month ago
Forms & Blueprints · by Japhy, 2 months ago
2 585 2 months ago
Forms & Blueprints · by FrViPofm, 2 months ago
5 615 2 months ago