Skip to content

Commit 3e508a1

Browse files
committed
fix(formanswers): execute show conditions when displaying formanswer
Signed-off-by: Thierry Bugier <[email protected]>
1 parent 9778b30 commit 3e508a1

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

inc/formanswer.class.php

+11-9
Original file line numberDiff line numberDiff line change
@@ -525,15 +525,25 @@ public function showForm($ID, $options = []) {
525525

526526
echo '<ol>';
527527
$domain = PluginFormcreatorForm::getTranslationDomain($_SESSION['glpilanguage'], $form->getID());
528+
529+
// Get fields populated with answers
530+
$answers = $this->getAnswers(
531+
$this->getID()
532+
);
533+
$answers['plugin_formcreator_forms_id'] = $form->getID();
534+
$visibility = PluginFormcreatorFields::updateVisibility($answers);
535+
528536
$sections = (new PluginFormcreatorSection)->getSectionsFromForm($form->getID());
529537
foreach ($sections as $section) {
530538
$sectionId = $section->getID();
531539

532540
// Section header
541+
$hiddenAttribute = $visibility[$section->getType()][$sectionId] ? '' : 'hidden=""';
533542
echo '<li'
534543
. ' class="plugin_formcreator_section"'
535544
. ' data-itemtype="' . PluginFormcreatorSection::class . '"'
536545
. ' data-id="' . $sectionId . '"'
546+
. " $hiddenAttribute"
537547
. '">';
538548

539549
// section name
@@ -544,14 +554,6 @@ public function showForm($ID, $options = []) {
544554
// Section content
545555
echo '<div>';
546556

547-
// Get fields populated with answers
548-
$answers = $this->getAnswers(
549-
$this->getID(),
550-
[
551-
PluginFormcreatorSection::getForeignKeyField() => $section->getID(),
552-
]
553-
);
554-
555557
// Display all fields of the section
556558
$lastQuestion = null;
557559
$questions = (new PluginFormcreatorQuestion)->getQuestionsFromSection($sectionId);
@@ -569,7 +571,7 @@ public function showForm($ID, $options = []) {
569571
}
570572
}
571573
}
572-
echo $question->getRenderedHtml($domain, $canEdit, $answers);
574+
echo $question->getRenderedHtml($domain, $canEdit, $answers, $visibility[$question->getType()][$question->getID()]);
573575
$lastQuestion = $question;
574576
}
575577
echo '</div>';

inc/question.class.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,9 @@ public function getDesignHtml() : string {
270270
* @param string $domain Translation domain of the form
271271
* @param boolean $canEdit Can the requester edit the field of the question ?
272272
* @param array $value Values all fields of the form
273+
* @param bool $isVisible is the question visible by default ?
273274
*/
274-
public function getRenderedHtml($domain, $canEdit = true, $value = []) : string {
275+
public function getRenderedHtml($domain, $canEdit = true, $value = [], $isVisible = true) : string {
275276
if ($this->isNewItem()) {
276277
return '';
277278
}
@@ -297,11 +298,13 @@ public function getRenderedHtml($domain, $canEdit = true, $value = []) : string
297298
$required = ($this->fields['required']) ? ' required' : '';
298299
$x = $this->fields['col'];
299300
$width = $this->fields['width'];
301+
$hiddenAttribute = $isVisible ? '' : 'hidden=""';
300302
$html .= '<div'
301303
. ' data-gs-x="' . $x . '"'
302304
. ' data-gs-width="' . $width . '"'
303305
. ' data-itemtype="' . self::class . '"'
304306
. ' data-id="' . $this->getID() . '"'
307+
. " $hiddenAttribute"
305308
. ' >';
306309
$html .= '<div class="grid-stack-item-content form-group ' . $required . '" id="form-group-field-' . $this->getID() . '">';
307310
$html .= $field->show($domain, $canEdit);

0 commit comments

Comments
 (0)