OPPG-459: "multiple" option for semantic type "select"

Specifies that the select shall handle multiple options.
Used by dynamicCheckboxes widget.
namespaces
Frank Ronny Larsen 2013-07-15 16:25:10 +02:00
parent fcc9ed4e24
commit 6d231499e3
1 changed files with 21 additions and 10 deletions

View File

@ -1332,9 +1332,14 @@ class H5PContentValidator {
} }
} }
if (isset($semantics->multiple) && $semantics->multiple) {
// Multichoice generates array of values. Test each one against valid // Multichoice generates array of values. Test each one against valid
// options, if we are strict. // options, if we are strict. First make sure we are working on an
if (is_array($select)) { // array.
if (!is_array($select)) {
$select = array($select);
}
foreach ($select as $key => $value) { foreach ($select as $key => $value) {
if ($strict && !isset($options[$value])) { if ($strict && !isset($options[$value])) {
$this->h5pF->setErrorMessage($this->h5pF->t('Invalid selected option in multiselect.')); $this->h5pF->setErrorMessage($this->h5pF->t('Invalid selected option in multiselect.'));
@ -1346,6 +1351,12 @@ class H5PContentValidator {
} }
} }
else { else {
// Single mode. If we get an array in here, we chop off the first
// element and use that instead.
if (is_array($select)) {
$select = $select[0];
}
if ($strict && !isset($options[$select])) { if ($strict && !isset($options[$select])) {
$this->h5pF->setErrorMessage($this->h5pF->t('Invalid selected option in select.')); $this->h5pF->setErrorMessage($this->h5pF->t('Invalid selected option in select.'));
$select = $semantics->options[0]->value; $select = $semantics->options[0]->value;