Checkboxlist in Component property not working

I’m building a component and I’m stuck on the properties. If you look at the code below, you’ll see two properties: contentType and tagCategories.

The component UI fails to load properly if tagCategories is present. When I remove it, it works fine.

It seems to be an issue with the checkboxlist type or optionsMethod as I can change the type to something else and there are no issues.

I’ve tried logging in getTagCategoryOptions() and it’s not getting called at all, so something is causing problems.

public function defineProperties()
    {
        return [
            'contentType' => [
                'title'       => 'Content Type',
                'description' => 'Specify whether this is for Blog or Success Story',
                'type'        => 'dropdown',
                'default'     => 'blog',
                'options'     => ['blog' => 'Blog', 'success_story' => 'Success Story']
            ],
            'tagCategories' => [
                'title'       => 'Tag Categories',
                'description' => 'Select the tag categories to display',
                'type'        => 'checkboxlist',
                'optionsMethod' => 'getTagCategoryOptions'
            ]
        ];
    }

    public function getTagCategoryOptions()
    {
        $categories = TagCategory::orderBy('name')->pluck('name', 'slug')->toArray();
        return $categories ?? [];
    }

I’ve also tried this code as well after desperately asking ChatGPT, but still no luck:

public function defineProperties()
{
    return [
        'contentType' => [
            'title'       => 'Content Type',
            'description' => 'Specify whether this is for Blog or Success Story',
            'type'        => 'dropdown',
            'default'     => 'blog',
            'options'     => ['blog' => 'Blog', 'success_story' => 'Success Story']
        ],
        'tagCategories' => [
            'title'       => 'Tag Categories',
            'description' => 'Select the tag categories to display',
            'type'        => 'checkboxlist'
        ]
    ];
}

public function getPropertyOptions($property)
{
    if ($property === 'tagCategories') {
        return TagCategory::orderBy('name')->pluck('name', 'slug')->toArray();
    }
    return [];
}

Any help much appreciated!

remove this line:

then try your component again. OC will complain that a method is missing inside the compoennt.
Take the name of the method it requires and implement it.

My guess is that it should be public function getTagCategoriesOptions() instead of public function getTagCategoryOptions()

Thank you - I really appreciate your reply.

I’ve tried removing that line but I don’t get any error message. It just silently fails. (I know the feeling!)

I did also try changing the function name to getTagCategoriesOptions() but that does nothing either.

Hi @tillathenun,

You need to use Inspector Types for the Component, specifically the type set.

Perfect! Thanks so much!

then i think the type checkboxlist does not exist for component properties.