Making select beeing able to be optional
parent
888a46844b
commit
5b8836b5be
|
@ -2852,6 +2852,7 @@ class H5PContentValidator {
|
||||||
* @param $semantics
|
* @param $semantics
|
||||||
*/
|
*/
|
||||||
public function validateSelect(&$select, $semantics) {
|
public function validateSelect(&$select, $semantics) {
|
||||||
|
$optional = isset($semantics->optional) && $semantics->optional;
|
||||||
$strict = FALSE;
|
$strict = FALSE;
|
||||||
if (isset($semantics->options) && !empty($semantics->options)) {
|
if (isset($semantics->options) && !empty($semantics->options)) {
|
||||||
// We have a strict set of options to choose from.
|
// We have a strict set of options to choose from.
|
||||||
|
@ -2871,7 +2872,7 @@ class H5PContentValidator {
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($select as $key => &$value) {
|
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.'));
|
$this->h5pF->setErrorMessage($this->h5pF->t('Invalid selected option in multi-select.'));
|
||||||
unset($select[$key]);
|
unset($select[$key]);
|
||||||
}
|
}
|
||||||
|
@ -2887,7 +2888,7 @@ class H5PContentValidator {
|
||||||
$select = $select[0];
|
$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.'));
|
$this->h5pF->setErrorMessage($this->h5pF->t('Invalid selected option in select.'));
|
||||||
$select = $semantics->options[0]->value;
|
$select = $semantics->options[0]->value;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue