Making select beeing able to be optional

pull/25/head
Paal Joergensen 2016-08-29 15:54:48 +02:00
parent 888a46844b
commit 5b8836b5be
1 changed files with 3 additions and 2 deletions

View File

@ -2852,6 +2852,7 @@ class H5PContentValidator {
* @param $semantics
*/
public function validateSelect(&$select, $semantics) {
$optional = isset($semantics->optional) && $semantics->optional;
$strict = FALSE;
if (isset($semantics->options) && !empty($semantics->options)) {
// We have a strict set of options to choose from.
@ -2871,7 +2872,7 @@ class H5PContentValidator {
}
foreach ($select as $key => &$value) {
if ($strict && !isset($options[$value])) {
if ($strict && !$optional && !isset($options[$value])) {
$this->h5pF->setErrorMessage($this->h5pF->t('Invalid selected option in multi-select.'));
unset($select[$key]);
}
@ -2887,7 +2888,7 @@ class H5PContentValidator {
$select = $select[0];
}
if ($strict && !isset($options[$select])) {
if ($strict && !$optional && !isset($options[$select])) {
$this->h5pF->setErrorMessage($this->h5pF->t('Invalid selected option in select.'));
$select = $semantics->options[0]->value;
}