From 19f0395698b3b25714ea5183150cd6c5a9c3af7a Mon Sep 17 00:00:00 2001 From: Stanislas Date: Thu, 13 Oct 2022 10:47:41 +0200 Subject: [PATCH] fix(fields): add default value to prevent SQL error (#2965) --- inc/field/fieldsfield.class.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/inc/field/fieldsfield.class.php b/inc/field/fieldsfield.class.php index 08acf5e74..e8ee6e9fb 100644 --- a/inc/field/fieldsfield.class.php +++ b/inc/field/fieldsfield.class.php @@ -536,7 +536,15 @@ public function parseAnswerValues($input, $nonDestructive = false): bool { $decodedValues = json_decode($this->question->fields['values'], JSON_OBJECT_AS_ARRAY); $field_name = $decodedValues['dropdown_fields_field'] ?? ''; $dropdown_field_name = "plugin_fields_" . $decodedValues['dropdown_fields_field'] . "dropdowns_id" ?? ''; - $value = ''; + + // compute default value + $field = new PluginFieldsField(); + $field->getFromDbByCrit(['name' => $field_name]); + if ($field->fields['type'] == 'dropdown') { + $value = 0; + } else { + $value = ''; + } if (isset($input[$field_name])) { $value = $input[$field_name];