Really strange panel site behavior with checkboxes extended field

I have extended a checkboxes field (Kirby 2.3.2). The code does not do much, it just replaces the options with an array from a database:

class CategoriesField extends CheckboxesField {
	public function options() {
		$sql = SqlCategories::get();
		$results = db::query($sql);

		foreach( $results as $data ) {
			$categories[$data->category_name] = $data->category_name;


	    return $categories;

How it looks on a panel page

It works like expected:

How it looks on panel site

The items doesn’t get checked, instead they disapear when they are saved. I checked the text file and they are saved correctly.

I don’t have any hooks.

I tested to change my code to this:

class CategoriesField extends CheckboxesField {

and with blueprint options:

    label: Kategorier
    type: categories
      text1: text1
      text2: text2

Suddenly the checkboxes are working again. However, I get another strange issue. I don’t think I should get a warning if the checkboxes are empty.

My real issue is the first one, why the items disapear when I populate them from a database.

  • Why does the items disapear on site but not on a normal page?
  • Why does this only happends with items populated from a database?
  • Why does a warning appear when no checkboxes are filled in?
  • Most important, how can I get around it?

I think I found a solution to the error. The sql seems to have some kind of dependency of the page and that did not work in site.

Unfortunately, I can’t test your database example. But I can’ t reproduce the issue with the empty checkboxes in a 2.3.2 test installation.

Have you tested your field with Kirby 2.4.0 beta? If so, do you get the same issue?

Do you have any extensions installed (I bet you have :wink:). Have you tried without these extensions or with a fresh starterkit?

Edit: Oh, I didn’t see your last post before posting mine …

Edit2: The solution does not explain why the page cannot be saved with empty checkboxes.

I did not add any code to my “solution” because it’s a bit unsafe and not so beautiful, but I’ll do it now anyway.

This function was used and it’s similar to an unlimited loop. I excluded checkboxes from the field by excluding them from the same list. Really stupid. :slight_smile:

public static function excludeSiteCategories() {
	$exclude = "\n";
	foreach( site()->categories()->split(',') as $item ) {
		$exclude .= "\t\t'" . $item . "',\n";
	$exclude = substr($exclude, 0, -2);
	$part = '';
	if( ! empty( $exclude ) ) {
		$part = " HAVING sum( categories.slug IN (" . $exclude . ") )=0 ";
	return $part;

Edit2: The solution does not explain why the page cannot be saved with empty checkboxes.

That’s still strange. The plugins I use is:

EDIT: It does not seems to have anything to do with my plugins. I deactivated them.

I have a simular issue with checkboxes, but it’s when I have more than 50 results kirby hangs up. It’s like for each option in checkboxes, it’s requiring then checking if it existists, then requires again.

It works with any other type of field. Radio buttons, etc. Just not checkboxes.