Skip to content

Commit ea185be

Browse files
committed
fix(question): missing conditions count after update
1 parent 936ccd4 commit ea185be

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

ajax/question_update.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@
5959
http_response_code(500);
6060
exit();
6161
}
62-
echo json_encode(['name' => Sanitizer::unsanitize($question->fields['name'])], JSON_UNESCAPED_UNICODE);
62+
echo json_encode(['name' => $question->getDesignLabel()], JSON_UNESCAPED_UNICODE);

inc/question.class.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,22 @@ public static function showForForm(CommonDBTM $item, $withtemplate = '') {
191191
return true;
192192
}
193193

194+
public function getDesignLabel(): string {
195+
$questionId = $this->getID();
196+
$nb = (new DBUtils())->countElementsInTable(PluginFormcreatorCondition::getTable(), [
197+
'itemtype' => PluginFormcreatorQuestion::getType(),
198+
'items_id' => $questionId,
199+
]);
200+
$sectionId = $this->fields[PluginFormcreatorSection::getForeignKeyField()];
201+
$onclick = 'plugin_formcreator.showQuestionForm(' . $sectionId . ', ' . $questionId . ');';
202+
$html = '<a href="javascript:' . $onclick . '" data-field="name">';
203+
$html .= "<sup class='plugin_formcreator_conditions_count' title='" . __('Count of conditions', 'formcreator') ."'>$nb</sup>";
204+
$html .= empty($this->fields['name']) ? '(' . $questionId . ')' : $this->fields['name'];
205+
$html .= '</a>';
206+
207+
return $html;
208+
}
209+
194210
/**
195211
* Get the HTML for the question in form designer
196212
*
@@ -218,16 +234,8 @@ public function getDesignHtml() : string {
218234

219235
// Question name
220236
$html .= $field->getHtmlIcon() . '&nbsp;';
221-
$onclick = 'plugin_formcreator.showQuestionForm(' . $sectionId . ', ' . $questionId . ');';
222-
$html .= '<a href="javascript:' . $onclick . '" data-field="name">';
223237
// Show count of conditions
224-
$nb = (new DBUtils())->countElementsInTable(PluginFormcreatorCondition::getTable(), [
225-
'itemtype' => PluginFormcreatorQuestion::getType(),
226-
'items_id' => $this->getID(),
227-
]);
228-
$html .= "<sup class='plugin_formcreator_conditions_count' title='" . __('Count of conditions', 'formcreator') ."'>$nb</sup>";
229-
$html .= empty($this->fields['name']) ? '(' . $questionId . ')' : $this->fields['name'];
230-
$html .= '</a>';
238+
$html .= $this->getDesignLabel();
231239

232240
// Delete the question
233241
$html .= "<span class='form_control pointer'>";

js/scripts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ var plugin_formcreator = new function() {
780780
displayAjaxMessageAfterRedirect();
781781
}).done(function(data) {
782782
var question = $('.plugin_formcreator_form_design[data-itemtype="PluginFormcreatorForm"] [data-itemtype="PluginFormcreatorQuestion"][data-id="' + questionId + '"]');
783-
question.find('[data-field="name"]').text(data['name'])
783+
$(question.find('[data-field="name"]')).replaceWith(data['name']);
784784
that.resetTabs();
785785
});
786786

0 commit comments

Comments
 (0)