mardi 5 avril 2016

CakePHP 3 - Checkbox list, formatResults->combine, add template

TODO

  • Checkbox list with key - value pairs.
  • Key = id.
  • Value (label) = three values combined. Only used for displaying data to the user.

What I have now:

$a->formatResults(function($results) {
    return $results->combine(
        'id',
        function($row) {
            return ' | ' . $row['_matchingData']['A']->name . ' |' . $row['_matchingData']['B']->name . '| . $row['C'] . '"';
        }
    );
});

What I tried:

$a->formatResults(function($results) {
    return $results->combine(
        'id',
        function($row) {
            return '
                <div class="row">
                    <div class="large-4 columns">
                        ' . $row['_matchingData']['A']->name . '
                    </div>
                    <div class="large-4 columns">
                        ' . $row['_matchingData']['B']->name . '
                    </div>
                    <div class="large-4 columns">
                        ' . $row['C'] . '
                    </div>
                </div>
            ';
        }
    );
});

Current template (.ctp)

echo $this->Form->input('a._ids', [
    'options' => $a,
    'multiple' => 'checkbox',
    'label' => false,
    'templates' => [
        'inputContainer' => '<div id="scroll_a" class="scrollable_input">{{content}}</div>'
    ]
]);

What happens now

The html is printed as 'plain' text.

What I actually like to have is that each checkbox is placed in a <div class="row> and that the checkbox is placed in a <div class="large-3 columns"> and every other three values too.




Aucun commentaire:

Enregistrer un commentaire