Skip to content

Commit

Permalink
fix(QuestionCondition): inconsistency in selectors
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Nov 23, 2018
1 parent d0c5cce commit ce7444f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion inc/field.class.php
Expand Up @@ -70,7 +70,7 @@ public function getValueForTarget() {
public function show($canEdit = true) {
$required = ($canEdit && $this->fields['required']) ? ' required' : '';

echo '<div class="form-group ' . $required . '" id="form-group-formcreator_field_' . $this->fields['id'] . '">';
echo '<div class="form-group ' . $required . '" id="form-group-field-' . $this->fields['id'] . '">';
echo '<label for="formcreator_field_' . $this->fields['id'] . '">';
echo $this->getLabel();
if ($canEdit && $this->fields['required']) {
Expand Down
23 changes: 11 additions & 12 deletions inc/fields.class.php
Expand Up @@ -268,11 +268,11 @@ public static function isVisible($id, $fields) {
} else {
switch ($currentLogic) {
case 'AND' :
$return &= $value;
$return = ($return and $value);
break;

case 'OR' :
$return |= $value;
$return = ($return or $value);
break;

default :
Expand All @@ -282,28 +282,27 @@ public static function isVisible($id, $fields) {

if ($currentLogic == 'AND' && $nextLogic != 'AND') {
if ($lowPrecedenceLogic == 'OR') {
$return |= $lowPrecedenceReturnPart;
$return = ($return or $lowPrecedenceReturnPart);
} else {
$return ^= $lowPrecedenceReturnPart;
$return = ($return xor $lowPrecedenceReturnPart);
}
}
}

// Ensure the low precedence part is used if last condition has logic == AND
if ($lowPrecedenceLogic == 'OR') {
$return |= $lowPrecedenceReturnPart;
$return = ($return or $lowPrecedenceReturnPart);
} else {
$return ^= $lowPrecedenceReturnPart;
$return = ($return xor $lowPrecedenceReturnPart);
}

unset($evalQuestion[$id]);

// If the field is hidden by default, show it if condition is true
if ($question->fields['show_rule'] == 'hidden') {
return ($return == true);

// else show it if condition is false
// If the field is hidden by default, show it if condition is true
return $return;
} else {
// else show it if condition is false
return !$return;
}
}
Expand All @@ -313,7 +312,7 @@ public static function isVisible($id, $fields) {
*
* @param array $input values of all fields of the form
*
* @rturn array
* @return array
*/
public static function updateVisibility($input) {
$fields = [];
Expand All @@ -332,7 +331,7 @@ public static function updateVisibility($input) {
}

$questionToShow = [];
foreach ($input as $id => $value) {
foreach ($fields as $id => $value) {
$questionToShow[$id] = PluginFormcreatorFields::isVisible($id, $fields);
}

Expand Down
15 changes: 8 additions & 7 deletions js/scripts.js.php
Expand Up @@ -596,17 +596,18 @@ function formcreatorShowFields(form) {
}
var i = 0;
for (var questionKey in questionToShow) {
var questionId = parseInt(questionKey.replace('formcreator_field_', ''));
var questionId = questionKey;
questionId = parseInt(questionKey.replace('formcreator_field_', ''));
if (!isNaN(questionId)) {
if (questionToShow[questionKey]) {
$('#form-group-' + questionKey).show();
$('#form-group-field' + questionKey).show();
i++;
$('#form-group-' + questionKey).removeClass('line' + (i+1) % 2);
$('#form-group-' + questionKey).addClass('line' + i%2);
$('#form-group-field' + questionKey).removeClass('line' + (i+1) % 2);
$('#form-group-field' + questionKey).addClass('line' + i%2);
} else {
$('#form-group-' + questionKey).hide();
$('#form-group-' + questionKey).removeClass('line0');
$('#form-group-' + questionKey).removeClass('line1');
$('#form-group-field' + questionKey).hide();
$('#form-group-field' + questionKey).removeClass('line0');
$('#form-group-field' + questionKey).removeClass('line1');
}
}
}
Expand Down

0 comments on commit ce7444f

Please sign in to comment.