# Really strange panel site behavior with checkboxes extended field

**URL:** <https://forum.getkirby.com/t/really-strange-panel-site-behavior-with-checkboxes-extended-field/5523>\
**Category:** Questions\
**Tags:** v2\
**Created:** [October 17, 2016, 7:57am UTC](https://forum.getkirby.com/t/really-strange-panel-site-behavior-with-checkboxes-extended-field/5523 "2016-10-17T07:57:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [October 17, 2016, 7:57am UTC](https://forum.getkirby.com/t/really-strange-panel-site-behavior-with-checkboxes-extended-field/5523/1 "2016-10-17T07:57:00Z")

</div>

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:

```php
<?php
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;
		}

		asort($categories);

	    return $categories;
	}
}

```

**How it looks on a panel page**

It works like expected:

 ![](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/f/fc1f5de459840f5c9242777494fb5c382713a3d1.gif)

**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.

 ![](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/6/630b597f39f23c99c0126dabb96aabd36dd15b11.gif)

I don’t have any hooks.

I tested to change my code to this:

```php
<?php
class CategoriesField extends CheckboxesField {
}

```

and with blueprint options:

```plaintext
fields:
  categories:
    label: Kategorier
    type: categories
    options:
      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.

 ![](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/8/898a2938654a6315ed61d7339e2752d119fee83d.png)

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?

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [October 17, 2016, 8:20am UTC](https://forum.getkirby.com/t/really-strange-panel-site-behavior-with-checkboxes-extended-field/5523/2 "2016-10-17T08:20:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [October 17, 2016, 8:23am UTC](https://forum.getkirby.com/t/really-strange-panel-site-behavior-with-checkboxes-extended-field/5523/3 "2016-10-17T08:23:57Z")

</div>

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 😉). 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.

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [October 17, 2016, 8:44am UTC](https://forum.getkirby.com/t/really-strange-panel-site-behavior-with-checkboxes-extended-field/5523/4 "2016-10-17T08:44:38Z")

</div>

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. 🙂

```php
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:

- [GitHub - kirby-deprecated-plugins/kirby-html-minifier: Minify the html output of a site built with Kirby CMS](https://github.com/jenstornell/kirby-html-minifier)
- [https://github.com/jenstornell/kirby-init-controller](https://github.com/jenstornell/kirby-init-controller)
- [GitHub - kirby-deprecated-plugins/kirby-headline-jump: Kirby Panel headline helper plugin for Kirby CMS](https://github.com/jenstornell/kirby-headline-jump)

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

---

<div class="post-metadata">

**Author:** ![bbarclay](https://avatars.discourse-cdn.com/v4/letter/b/96bed5/32.png) [@bbarclay](https://forum.getkirby.com/u/bbarclay)\
**Post date:** [December 13, 2017, 4:54pm UTC](https://forum.getkirby.com/t/really-strange-panel-site-behavior-with-checkboxes-extended-field/5523/5 "2017-12-13T16:54:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:30pm UTC](https://forum.getkirby.com/t/really-strange-panel-site-behavior-with-checkboxes-extended-field/5523/6 "2025-02-06T17:30:18Z")

</div>

Archived on February 6, 2025, 5:30pm UTC


