Array as value in Editor -> options

Array as value in Editor -> options

Jhon MoranoJhon Morano Posts: 2Questions: 1Answers: 0
edited January 2016 in Free community support

I have this:

Field::inst( 'valabilitate' ) ->options( 'tarife', array('tconcesiune', 'zconcesiune'), array('tconcesiune', 'zconcesiune') 

The label is corectly taken but the value i cant take as an array.
<b>Warning</b>: Illegal offset type in.....

this works:

Field::inst( 'valabilitate' ) ->options( 'tarife','tconcesiune', array('tconcesiune', 'zconcesiune') 

but this way i cant take the value also as an array.

I just need the value to be the same as the label.

Any suggestions or help is much apreciated!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 64,941Questions: 1Answers: 10,756 Site admin
    Answer ✓

    Hi,

    Unfortunately only the label can be given as an array (and will be combined in order to get the string output). There is no built in option to give an array for the value (I presume you want it concatenated into a single string value?).

    You would need to use a custom method if you want to use multiple database columns as the value for your select field.

    Allan

  • Jhon MoranoJhon Morano Posts: 2Questions: 1Answers: 0

    thx Allan for the fast response
    now it works :D

    Code for others:

    ->options( function () use ( $db ) {
                $attrList = $db->selectDistinct (
                        'tarife',
                        ['tconcesiune', 'zconcesiune', 'pconcesiune']);
                       $out[] = array('value' => '', 'label' => 'Alege valabilitatea');
                while ( $row = $attrList->fetch() ) {
             
                    $out[] = array(
                            "value" => $row['tconcesiune'].' Ani - Zona '.$row['zconcesiune'].' - '. $row['pconcesiune'] .' lei',
                            "label" => $row['tconcesiune'].' Ani - Zona '.$row['zconcesiune'].' - '. $row['pconcesiune'] .' lei'
                    ); }      
                return $out;
                })
    
  • borconiborconi Posts: 56Questions: 19Answers: 1

    Thanks @allan and @Jhon Morano this put me on the right track to solve my problem.
    P.S. It made me smile when I realized what language is the code in :smile:

This discussion has been closed.