user1350070
user1350070

Reputation: 15

Agile Toolkit 4.2 ... reference field type breaking with model

This is a simple re-write of the example code for a reference field:

class page_LoadResults extends Page {
function init(){
    parent::init();
    $p=$this;
    $f=$p->add('Form');

$c=$p->add('Model_Season');
$f->addField('reference','Season')
    ->setValueList($c)
    ->validateNotNull()
    ->add('Icon',null,'after_field')
    ->set('arrows-left3')
    ->addStyle('cursor','pointer')
    ->js('click',$f->js()->reload())
    ;

When called I get an error message:

\atk4\lib\Form/Field.php:652 [2] htmlspecialchars() expects parameter 1 to be string, array given

Looking at the code, around line 648 in Field.php

    foreach($this->getValueList() as $value=>$descr){
        // Check if a separator is not needed identified with _separator<
        $output.=
            $this->getOption($value)
            .htmlspecialchars($descr)
            .$this->getTag('/option');
    }

Is indeed apparently creating $descr as an array of ($value,descr)

IS this a bug or am I off base. Thanks.

Upvotes: 1

Views: 576

Answers (1)

jancha
jancha

Reputation: 4967

use atk 4.2 syntax

<?php

class page_b extends Page {
    function init(){
        parent::init();
        $p=$this;
        $f=$p->add('Form');
        $field = $f->addField('Dropdown','Season');
        $field->setModel("a");
        $field
            ->validateNotNull()
            ->add('Icon',null,'after_field')
            ->set('arrows-left3')
            ->addStyle('cursor','pointer')
            ->js('click',$f->js()->reload())
            ;
    }   
}
  1. Pay attention to addField("Dropdown")
  2. use setModel rather than setValueList($model);

Upvotes: 2

Related Questions