Skip to content
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Fixed

- Force float `datatype` of `numeric` fields for fix the search option
Comment thread
Lainow marked this conversation as resolved.
Outdated
- Fix container update from other context (like plugins)

## [1.21.19] - 2025-02-03
Expand Down
31 changes: 28 additions & 3 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,12 +341,37 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype)
/** @var \DBmysql $DB */
global $DB;

$searchopt = &Search::getOptions($itemtype);
$table = $searchopt[$ID]['table'];
$field = $searchopt[$ID]['field'];
$searchopt = &Search::getOptions($itemtype);
$table = $searchopt[$ID]['table'];
$field = $searchopt[$ID]['field'];
$pfields_type = $searchopt[$ID]['pfields_type'];
Comment thread
Lainow marked this conversation as resolved.
Outdated

$field_field = new PluginFieldsField();

if (
$field_field->getFromDBByCrit(
[
'name' => $field
],
)
&& $pfields_type == 'number'
Comment thread
Lainow marked this conversation as resolved.
) {
// if 'number' field with name is found with searchtype 'equals' or 'notequals'
// update WHERE clause with `$table_$field.$field` because without `$table_$field.id` is used
if ($searchtype == 'equals' || $searchtype == 'notequals') {
$operator = ($searchtype == 'equals') ? '=' : '!=';
return $link . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . $operator . ' ' . $DB->quoteValue($val) ;
} else {
// if 'number' field with name is found with <= or >= or < or > search
$val = html_entity_decode($val);
if (preg_match('/(<=|>=|>|<)/', $val, $matches)) {
$operator = $matches[1];
$val = trim(str_replace($operator, '', $val));
return $link . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . $operator . ' ' . $DB->quoteValue($val);
}
}
}

// if 'multiple' field with name is found -> 'Dropdown-XXXX' case
// update WHERE clause with LIKE statement
if (
Expand Down
4 changes: 3 additions & 1 deletion inc/container.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1962,7 +1962,9 @@ public static function getAddSearchOptions($itemtype, $containers_id = false)
$opt[$i]['datatype'] = 'text';
break;
case 'number':
$opt[$i]['datatype'] = 'float';
// change datatype to string because decimal
Comment thread
Lainow marked this conversation as resolved.
Outdated
$opt[$i]['datatype'] = 'string';
$opt[$i]['searchtype'] = ['contains', 'notcontains', 'equals', 'notequals'];
Comment thread
Rom1-B marked this conversation as resolved.
break;
case 'date':
case 'datetime':
Expand Down