4

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.

2

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' => 'North Island'),
 array('label' => 'Foo', 'value' => 'foo'),
 array('label' => 'Bar', 'value' => 'bar')
 array('optgroup' => 'South Island'),
 array('label' => 'Baz', 'value' => 'baz')
);

This then would output it like this in the admin area

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.