Permalink
Browse files

fix(views): input/select view can select options more reliably

If `$vars['options']` is given as an array and an element `$option` is
also an array, we no longer emit a notice and properly set the `selected`
attribute based on `$option['text']`.

Fixes #10154
  • Loading branch information...
mrclay committed Sep 6, 2016
1 parent 98843dc commit af103c7ec700c2d6ca39f29e9ff57f71ef08447c
Showing with 8 additions and 2 deletions.
  1. +8 −2 views/default/input/select.php
@@ -82,17 +82,23 @@
if (is_array($options)) {
foreach ($options as $option) {
$option_attrs = ['selected' => in_array((string)$option, $value)];
if (is_array($option)) {
$text = elgg_extract('text', $option, '');
unset($option['text']);
if (!$text) {
elgg_log('No text defined for input/select option', 'ERROR');
}
$option_attrs = [
'selected' => in_array((string)$text, $value),
];
$option_attrs = array_merge($option_attrs, $option);
} else {
$option_attrs = [
'selected' => in_array((string)$option, $value),
];
$text = $option;
}

0 comments on commit af103c7

Please sign in to comment.