MDL-64151 form: autocomplete element remove last choice

This is the same situation as was in MDL-56864 but now in 'course', 'autocomplete' and 'select' elements
- if the element allows multiple selection it is impossible to remove the last element
This commit is contained in:
Marina Glancy
2019-04-11 16:46:33 +02:00
parent 12476a35a6
commit 98af4c736d
8 changed files with 32 additions and 5 deletions
+4 -2
View File
@@ -166,8 +166,9 @@ class MoodleQuickForm_select extends HTML_QuickForm_select implements templatabl
*/
function exportValue(&$submitValues, $assoc = false)
{
$emptyvalue = $this->getMultiple() ? [] : '';
if (empty($this->_options)) {
return $this->_prepareValue(null, $assoc);
return $this->_prepareValue($emptyvalue, $assoc);
}
$value = $this->_findValue($submitValues);
@@ -187,7 +188,7 @@ class MoodleQuickForm_select extends HTML_QuickForm_select implements templatabl
}
if (empty($cleaned)) {
return $this->_prepareValue(null, $assoc);
return $this->_prepareValue($emptyvalue, $assoc);
}
if ($this->getMultiple()) {
return $this->_prepareValue($cleaned, $assoc);
@@ -223,6 +224,7 @@ class MoodleQuickForm_select extends HTML_QuickForm_select implements templatabl
$options[] = $o;
}
$context['options'] = $options;
$context['nameraw'] = $this->getName();
return $context;
}