How can I add an option group to the select Macro from CraftCMS forms macros I'm trying to list out a select element with option groups and options using the awesome for macro that Pixel and Tonic created.

I have imported the macros and am calling the select one like so:

{{ forms.select({
          id: 'ccs',
          label: "Collection store:",
          class: '',
          name: 'fulfilmentStore',
          hasOptgroups: true,
          options: [
            {'optgroup':'North Island', 'value': 'NI1',},
            {'optgroup':'South Island'}
          ],
        }) }}


I pretty sure I have to have another lot of options sitting under the optGroup but can't get the syntax right.

Thanks in advance.
I had the same issue and managed to get it working like so:

{{ forms.selectField({
    options :[
     {optgroup:'North Island'},
     {label : 'Foo', value: 'foo'},
     {label : 'Bar', value: 'bar'},
     {optgroup:'South Island'},
     {label : 'Baz', value: 'baz'}
    ],
    name: name,
    value : value
})}}


So I guess in php (if working from a plugin) your array would need to look like:

array(
 array('optgroup' =&gt; 'North Island'),
 array('label' =&gt; 'Foo', 'value' =&gt; 'foo'),
 array('label' =&gt; 'Bar', 'value' =&gt; 'bar')
 array('optgroup' =&gt; 'South Island'),
 array('label' =&gt; 'Baz', 'value' =&gt; 'baz')
);


This then would output it like this in the admin area