Custom List Field

Great, thank you for this. I hope they implement this natively on kirby… i really missed a simple list field for many parts of my site where I needed to set editable default options for editors…

Hi @timoetting,

Love the List Field and I hope it makes it to the core just the way it is (with a delete button!)

On topic… I wonder if anyone has a use for drag-and-drop across multiple list fields? Just like in the subpages editor which allows dragging pages between Published and Unpublished. Could be a nice way to categorise all sorts of content on a page. An example use case might be a todo list, where you can drag an item from Pending to Completed. Maybe the idea is too crazy though – cross-field awareness would be quite a new paradigm in Kirby. Anyone’s thoughts?

If you were to build something like a to-do list field, it would be one field with several inputs (lists).
There’s already a great working example of this with this plugin:

Although this plugin is only to be used with modules, it’s a great starter to see how multi-list drag-and-drop can work!

Thanks Thiousi, that’s a good starting point for the JS and styling. I’ll have a crack and if I get anywhere I’ll post a link here!

1 Like

Not working at all for me. I installed directly into site/fields/list as suggested. Any suggestions?

@AdamRasheed: What exactly does not work? Do you get an error message? The file structure should look like this

It’s set up exactly like that but in the panel the list field just looks like a text field.

Just start typing into the field … and you’ll see a surprise :slight_smile:

2 Likes

What do you get instead?

Even is this is probably not the intended use of this field, it will work like this using the kirbytext() helper

<?php
$items = $page->field()->yaml();
foreach($items as $item) {
  echo kirbytext($item);
}

That’s also possible with some regex voodoo:

// you can put this method into a methods.php in /site/plugins
function ktRaw($content) {
   $text = kirbytext($content);
   return preg_replace('/(.*)<\/p>/', '$1', preg_replace('/<p>(.*)/', '$1', $text));
}

$items = $page->field()->yaml();
foreach($items as $item) {
  echo ktRaw($item);
}

Hey @fooness,

I’ve recently created a custom field method that will help you with exactly that problem. Have a look at the corresponding post:

You can find the method as a plugin on github

Great, thanks for sharing, @timoetting . This is great if you don’t need any markdown parsing in your field. It will not work if you just want to get rid of p tags but keep the rest of the markdown parsing.

From the PHP docs:
http://php.net/manual/en/language.basic-syntax.phptags.php

If a file is pure PHP code, it is preferable to omit the PHP closing tag at the end of the file. This prevents accidental whitespace or new lines being added after the PHP closing tag, which may cause unwanted effects because PHP will start output buffering when there is no intention from the programmer to send any output at that point in the script.

1 Like