Fix FormValidator's SelectAjax when exporting value - refs #8134

ofaj
Angel Fernando Quiroz Campos 9 years ago
parent d153b6fa7b
commit b9dac78374
  1. 22
      main/admin/settings.lib.php
  2. 15
      main/inc/lib/formvalidator/Element/SelectAjax.php

@ -1506,22 +1506,22 @@ function generate_settings_form($settings, $settings_by_access_list)
case 'custom':
break;
case 'select_course':
$courseSelect = $form->addElement(
'select_ajax',
$row['variable'],
[
get_lang($row['title']),
get_lang($row['comment']),
],
null,
['url' => api_get_path(WEB_AJAX_PATH) . 'course.ajax.php?a=search_course']
);
$courseSelectOptions = [];
if (!empty($row['selected_value'])) {
$course = $em->find('ChamiloCoreBundle:Course', $row['selected_value']);
$courseSelect->addOption($course->getTitle(), $course->getCode(), ['selected' => 'selected']);
$courseSelectOptions[$course->getId()] = $course->getTitle();
}
$form->addElement(
'select_ajax',
$row['variable'],
[get_lang($row['title']), get_lang($row['comment'])],
$courseSelectOptions,
['url' => api_get_path(WEB_AJAX_PATH) . 'course.ajax.php?a=search_course']
);
$default_values[$row['variable']] = $row['selected_value'];
break;
}

@ -115,4 +115,19 @@ JS;
return parent::toHtml() . $html;
}
/**
* We check the options and return only the values that _could_ have been
* selected. We also return a scalar value if select is not "multiple"
*/
function exportValue(&$submitValues, $assoc = false)
{
$value = $this->_findValue($submitValues);
if (!$value) {
$value = '';
}
return $this->_prepareValue($value, $assoc);
}
}

Loading…
Cancel
Save