carbon-fields icon indicating copy to clipboard operation
carbon-fields copied to clipboard

Option label support in set_header_template()

Open erikjoling opened this issue 8 years ago • 4 comments

I have a select field coded as followed:

->set_layout('tabbed-vertical')
->add_fields(array(
    Field::make('select','project')->add_options(array(
        25 => 'Project Name',
        37 => 'Second Project Name'
    ))
))
->set_header_template('<%- project %>')

Currently this returns the project id as the tab-label. But this isn't very useful. Is it possible to set the project name (array value) as header for my tabs?

Using 2.0

erikjoling avatar Aug 16 '17 09:08 erikjoling

Currently, this is not supported, however you can make use of Lodash template conditionals for a dirty and hacky solution by generating the template conditionals based on the options you pass to the field.

atanas-dev avatar Aug 16 '17 09:08 atanas-dev

Thank you Atanas, I'll give it a try

erikjoling avatar Aug 16 '17 09:08 erikjoling

Would love if this feature was available. The hacky solution doesn't work for me because the options array is a dynamically created list of posts that meet certain conditions.

aurooba avatar Mar 05 '19 21:03 aurooba

https://github.com/htmlburger/carbon-fields/issues/793#issuecomment-574587611 has a nice workaround

joostdekeijzer avatar Oct 27 '21 11:10 joostdekeijzer