Skip to content

Commit

Permalink
fix(formanswers): execute show conditions when displaying formanswer
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Mar 24, 2021
1 parent 9778b30 commit 3e508a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
20 changes: 11 additions & 9 deletions inc/formanswer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,15 +525,25 @@ public function showForm($ID, $options = []) {

echo '<ol>';
$domain = PluginFormcreatorForm::getTranslationDomain($_SESSION['glpilanguage'], $form->getID());

// Get fields populated with answers
$answers = $this->getAnswers(
$this->getID()
);
$answers['plugin_formcreator_forms_id'] = $form->getID();
$visibility = PluginFormcreatorFields::updateVisibility($answers);

$sections = (new PluginFormcreatorSection)->getSectionsFromForm($form->getID());
foreach ($sections as $section) {
$sectionId = $section->getID();

// Section header
$hiddenAttribute = $visibility[$section->getType()][$sectionId] ? '' : 'hidden=""';
echo '<li'
. ' class="plugin_formcreator_section"'
. ' data-itemtype="' . PluginFormcreatorSection::class . '"'
. ' data-id="' . $sectionId . '"'
. " $hiddenAttribute"
. '">';

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

// Get fields populated with answers
$answers = $this->getAnswers(
$this->getID(),
[
PluginFormcreatorSection::getForeignKeyField() => $section->getID(),
]
);

// Display all fields of the section
$lastQuestion = null;
$questions = (new PluginFormcreatorQuestion)->getQuestionsFromSection($sectionId);
Expand All @@ -569,7 +571,7 @@ public function showForm($ID, $options = []) {
}
}
}
echo $question->getRenderedHtml($domain, $canEdit, $answers);
echo $question->getRenderedHtml($domain, $canEdit, $answers, $visibility[$question->getType()][$question->getID()]);
$lastQuestion = $question;
}
echo '</div>';
Expand Down
5 changes: 4 additions & 1 deletion inc/question.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,9 @@ public function getDesignHtml() : string {
* @param string $domain Translation domain of the form
* @param boolean $canEdit Can the requester edit the field of the question ?
* @param array $value Values all fields of the form
* @param bool $isVisible is the question visible by default ?
*/
public function getRenderedHtml($domain, $canEdit = true, $value = []) : string {
public function getRenderedHtml($domain, $canEdit = true, $value = [], $isVisible = true) : string {
if ($this->isNewItem()) {
return '';
}
Expand All @@ -297,11 +298,13 @@ public function getRenderedHtml($domain, $canEdit = true, $value = []) : string
$required = ($this->fields['required']) ? ' required' : '';
$x = $this->fields['col'];
$width = $this->fields['width'];
$hiddenAttribute = $isVisible ? '' : 'hidden=""';
$html .= '<div'
. ' data-gs-x="' . $x . '"'
. ' data-gs-width="' . $width . '"'
. ' data-itemtype="' . self::class . '"'
. ' data-id="' . $this->getID() . '"'
. " $hiddenAttribute"
. ' >';
$html .= '<div class="grid-stack-item-content form-group ' . $required . '" id="form-group-field-' . $this->getID() . '">';
$html .= $field->show($domain, $canEdit);
Expand Down

0 comments on commit 3e508a1

Please sign in to comment.