Not sure i undrstand sorry, how do i add that field to the blueprint after i create it?
I need the select field in the panel, on the page inside the main one. It isnt for the frontend.
Isnt there any option on this page that does that? http://getkirby.com/docs/cheatsheet/panel-fields/select
Ive been trying but the select keeps coming up empty.
<?php
class CategoryField extends BaseField {
public function __construct() {
$this->type = 'category';
$this->icon = 'chevron-down';
$this->label = 'category';
$this->options = array();
}
public function options() {
return FieldOptions::build($this);
}
public function option($value, $text, $selected = false) {
return new Brick('option', $this->i18n($text), array(
'value' => $value,
'selected' => $selected
));
}
public function input() {
$select = new Brick('select');
$select->addClass('selectbox');
$select->attr(array(
'name' => $this->name(),
'id' => $this->id(),
'required' => $this->required(),
'autocomplete' => $this->autocomplete(),
'autofocus' => $this->autofocus(),
'readonly' => $this->readonly(),
'disabled' => $this->disabled(),
));
$select = $select->append($this->option('', '', $this->value() == ''));
if($this->readonly()) {
$select->attr('tabindex', '-1');
}
if($this->page()->parent()->categorias()) {
$categories = $this->page()->parent()->categorias()->toStructure();
}
foreach($categories as $category) {
$category = $category->categoria();
$this->options[] = $category;
}
foreach($this->options() as $value => $text) {
$select->append($this->option($value, $text, $this->value() == $value));
}
$inner = new Brick('div');
$inner->addClass('selectbox-wrapper');
$inner->append($select);
$wrapper = new Brick('div');
$wrapper->addClass('input input-with-selectbox');
$wrapper->append($inner);
if($this->readonly()) {
$wrapper->addClass('input-is-readonly');
} else {
$wrapper->attr('data-focus', 'true');
}
return $wrapper;
}
}
Pls note that this will only work with the structure field called “categorias” and the field “categoria” within that structure field. If you rename the field, you have to change this bit of code.
It’s working, thanks for everything.
Hope i don’t get stuck anymore lol
This was probably the hardest part on my template, only problem with this is that categories with spaces break the code, i think ill add 2 fields to the structure, one for display and other for the code itself.
Another way of doing it would be to stick to the numbers as keys and map the keys to the values in your config file and call them via c::get() in your template.
I tried to apply this to a page of mine… same structure and idea (select in child pages loading values from a structure field) but I think something has changed since 2.1 update. I’m getting an error:
Warning: Illegal offset type in isset or empty in /Users/me/Sites/mysite/kirby/toolkit/lib/silo.php on line 30
The array manipulation on the code below must be doing something wrong:
Wish i could help, but i’m not using this anymore. I ended up having a page for each category and then use:
category:
label: Additional Category
type: select
options: query
query:
page: work
fetch: children
value: '{{uid}}'
text: ‘{{title}}’
Note: This will probably fail if either the event_type or event_name fields are empty, so you would either have to require the fields to be filled in or handle missing fields entries in the code. The external API solution I suggested in this thread Panel: querying "site.txt" structure fields as pages/subpages fields' values is probably the better solution.
This new code is giving me the same errors (imagem below)… I’m starting to doubt my local environment (php).
I’ve tried everything I could to fix it, but again… hit a wall
[edit] I didn’t invested much on the API solution you’ve mentioned because of the v::url() issue… and also because I didn’t wanted to fiddle with the core (scary stuff).
Your array manipulation was sound & solid @texnixe
[edit] Also Regarding the “why using [‘event_code’]”… just found out that when one changes the order in the structure field it changes the selected option in every page/subpage that uses it. So using the “code” will certify that the structure field’s content order won’t matter…