Skip to content

Commit

Permalink
media custom select validation fix: allow selection by index (for cus…
Browse files Browse the repository at this point in the history
…tom fields)
  • Loading branch information
hinanaya committed Jun 11, 2024
1 parent 1c183ec commit 08b4c79
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion models/media_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,10 @@ public function validate($args = [])
$metadata_value = $item['metadata_' . $metadata_field['name']];

// validate if select
if ($metadata_field['type'] == 'select' && $metadata_value != '' && array_search($metadata_value, $metadata_field['settings']->options) === false) {
// note that value can be selected by index as well, so only invalidate if neither value nor valid index is used
if ($metadata_field['type'] == 'select' && $metadata_value != ''
&& array_search($metadata_value, $metadata_field['settings']->options) === false
&& (! ctype_digit($metadata_value) || intval($metadata_value) < 0 || intval($metadata_value) > count($metadata_field['settings']->options) )) {
return array(false,$item['local_id'],$metadata_field['description'] . ' value not valid.');
}

Expand Down

0 comments on commit 08b4c79

Please sign in to comment.