Skip to content

Commit

Permalink
fix(checkboxesfield,multiselectfield): php warning
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Apr 17, 2023
1 parent 69731d1 commit 342c39e
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions inc/field/checkboxesfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,23 @@ public function showForm(array $options): void {

$value = [];
$items = json_decode($this->question->fields['default_values']);
foreach ($items as $item) {
if (trim($item) === '') {
continue;
}
if (!in_array($item, $this->getAvailableValues())) {
continue;
if ($items !== null) {
// when we edit an existing question
foreach ($items as $item) {
if (trim($item) === '') {
continue;
}
if (!in_array($item, $this->getAvailableValues())) {
continue;
}
$value[] = $item;
}
$value[] = $item;
$this->question->fields['default_values'] = implode("\r\n", $value);
$this->deserializeValue($this->question->fields['default_values']);
}
$this->question->fields['default_values'] = implode("\r\n", $value);
$this->question->fields['values'] = json_decode($this->question->fields['values']);
$this->question->fields['values'] = is_array($this->question->fields['values']) ? $this->question->fields['values'] : [];
$this->question->fields['values'] = implode("\r\n", $this->question->fields['values']);
$this->deserializeValue($this->question->fields['default_values']);

$parameters = $this->getParameters();
TemplateRenderer::getInstance()->display($template, [
Expand Down

0 comments on commit 342c39e

Please sign in to comment.