Merge branch 'MDL-64151-master' of git://github.com/marinaglancy/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2019-04-23 19:26:47 +02:00
commit 1e36bcfb67
8 changed files with 32 additions and 5 deletions

View File

@ -204,7 +204,7 @@ class MoodleQuickForm_autocomplete extends MoodleQuickForm_select {
// Normally this is cleaned as a side effect of it not being a valid option,
// but in this case we need to detect and skip it manually.
if ($value === '_qf__force_multiselect_submission' || $value === null) {
$value = '';
$value = $this->getMultiple() ? [] : '';
}
return $this->_prepareValue($value, $assoc);
} else {

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;
}

View File

@ -261,7 +261,6 @@ class MoodleQuickForm_tags extends MoodleQuickForm_autocomplete {
$url = new moodle_url('/tag/manage.php', array('tc' => $this->get_tag_collection()));
$context['managestandardtagsurl'] = $url->out(false);
}
$context['nameraw'] = $this->getName();
return $context;
}

View File

@ -1,6 +1,9 @@
{{< core_form/element-template-inline }}
{{$element}}
{{^element.frozen}}
{{#element.multiple}}
<input type="hidden" name="{{element.nameraw}}" value="_qf__force_multiselect_submission">
{{/element.multiple}}
<select class="custom-select {{#error}}is-invalid{{/error}}" name="{{element.name}}"
id="{{element.id}}"
{{#element.multiple}}multiple{{/element.multiple}}

View File

@ -1,6 +1,9 @@
{{< core_form/element-template }}
{{$element}}
{{^element.frozen}}
{{#element.multiple}}
<input type="hidden" name="{{element.nameraw}}" value="_qf__force_multiselect_submission">
{{/element.multiple}}
<select class="custom-select {{#error}}is-invalid{{/error}}" name="{{element.name}}"
id="{{element.id}}"
{{#element.multiple}}multiple{{/element.multiple}}

View File

@ -1,6 +1,9 @@
{{< core_form/element-template-inline }}
{{$element}}
{{^element.frozen}}
{{#element.multiple}}
<input type="hidden" name="{{element.nameraw}}" value="_qf__force_multiselect_submission">
{{/element.multiple}}
<select class="{{^element.multiple}}custom-select{{/element.multiple}}
{{#element.multiple}}form-control{{/element.multiple}}
{{#error}}is-invalid{{/error}}"

View File

@ -21,6 +21,7 @@
Context variables required for this template:
* id - Element id,
* nameraw - Raw Element name without '[]'
* name - Element name,
* label - Element label,
* multiple - multi select?,
@ -49,6 +50,7 @@
{
"element": {
"id": "id_maildisplay",
"nameraw": "maildisplay",
"name": "maildisplay",
"label": null,
"multiple": null,
@ -92,6 +94,9 @@
{{< core_form/element-template }}
{{$element}}
{{^element.frozen}}
{{#element.multiple}}
<input type="hidden" name="{{element.nameraw}}" value="_qf__force_multiselect_submission">
{{/element.multiple}}
<select class="{{^element.multiple}}custom-select{{/element.multiple}}
{{#element.multiple}}form-control{{/element.multiple}}
{{#error}}is-invalid{{/error}}"

View File

@ -49,7 +49,7 @@ class core_form_autocomplete_testcase extends basic_testcase {
$submission = array('testel' => 2);
$this->assertEquals($element->exportValue($submission), 2);
$submission = array('testel' => 3);
$this->assertNull($element->exportValue($submission));
$this->assertEquals('', $element->exportValue($submission));
// A select with multiple values validates the data.
$options = array('1' => 'One', 2 => 'Two');
@ -61,6 +61,18 @@ class core_form_autocomplete_testcase extends basic_testcase {
$element = new MoodleQuickForm_autocomplete('testel', null, array(), array('multiple'=>'multiple', 'ajax'=>'anything'));
$submission = array('testel' => array(2, 3));
$this->assertEquals($element->exportValue($submission), array(2, 3));
// A select with single value without anything selected.
$options = array('1' => 'One', 2 => 'Two');
$element = new MoodleQuickForm_autocomplete('testel', null, $options);
$submission = array();
$this->assertEquals('', $element->exportValue($submission));
// A select with multiple values without anything selected.
$options = array('1' => 'One', 2 => 'Two');
$element = new MoodleQuickForm_autocomplete('testel', null, $options, array('multiple' => 'multiple'));
$submission = array();
$this->assertEquals([], $element->exportValue($submission));
}
}