Skip to content

Commit

Permalink
fix(condition): broken UI when adding a conditionnable with conditions
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <[email protected]>
  • Loading branch information
btry committed Jan 28, 2020
1 parent f7cecdb commit 006b286
Show file tree
Hide file tree
Showing 20 changed files with 27 additions and 28 deletions.
2 changes: 1 addition & 1 deletion inc/fields/actorfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function getDesignSpecializationField() {
$additions .= '</td>';
$additions .= '</tr>';

$common = $common = parent::getDesignSpecializationField();
$common = parent::getDesignSpecializationField();
$additions .= $common['additions'];

return [
Expand Down
3 changes: 2 additions & 1 deletion inc/fields/checkboxesfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function getDesignSpecializationField() {
$additions .= '</td>';
$additions .= '</tr>';

$common = $common = parent::getDesignSpecializationField();
$common = parent::getDesignSpecializationField();
$additions .= $common['additions'];

return [
Expand Down Expand Up @@ -202,6 +202,7 @@ public function isValidValue($value) {
return true;
}

$value = Toolbox::stripslashes_deep($value);
foreach ($value as $item) {
if (trim($item) == '') {
return false;
Expand Down
2 changes: 1 addition & 1 deletion inc/fields/datefield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function getDesignSpecializationField() {
$additions .= '</td>';
$additions .= '</tr>';

$common = $common = parent::getDesignSpecializationField();
$common = parent::getDesignSpecializationField();
$additions .= $common['additions'];

return [
Expand Down
2 changes: 1 addition & 1 deletion inc/fields/datetimefield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function getDesignSpecializationField() {
$additions .= '</td>';
$additions .= '</tr>';

$common = $common = parent::getDesignSpecializationField();
$common = parent::getDesignSpecializationField();
$additions .= $common['additions'];

return [
Expand Down
2 changes: 1 addition & 1 deletion inc/fields/descriptionfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function isPrerequisites() {
}

public function getDesignSpecializationField() {
$common = $common = parent::getDesignSpecializationField();
$common = parent::getDesignSpecializationField();
$additions = $common['additions'];

return [
Expand Down
2 changes: 1 addition & 1 deletion inc/fields/dropdownfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function getDesignSpecializationField() {
$additions .= '</tr>';
$additions .= Html::scriptBlock("plugin_formcreator_changeDropdownItemtype($rand);");

$common = $common = parent::getDesignSpecializationField();
$common = parent::getDesignSpecializationField();
$additions .= $common['additions'];

return [
Expand Down
3 changes: 0 additions & 3 deletions inc/fields/emailfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ public function getDesignSpecializationField() {
$additions .= '<td></td>';
$additions .= '</tr>';

$common = $common = parent::getDesignSpecializationField();
$additions .= $common['additions'];

return [
'label' => $label,
'field' => $field,
Expand Down
2 changes: 1 addition & 1 deletion inc/fields/filefield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function isValid() {

public function isValidValue($value) {
// If the field is required it can't be empty
return (count($this->uploadData) > 0);
return (!$this->isRequired() || count($this->uploadData) > 0);
}

public static function getName() {
Expand Down
2 changes: 1 addition & 1 deletion inc/fields/floatfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function getDesignSpecializationField() {
$additions .= '<td></td>';
$additions .= '</tr>';

$common = $common = parent::getDesignSpecializationField();
$common = parent::getDesignSpecializationField();
$additions .= $common['additions'];

return [
Expand Down
2 changes: 1 addition & 1 deletion inc/fields/hiddenfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function getDesignSpecializationField() {
$additions .= '<td></td>';
$additions .= '</tr>';

$common = $common = parent::getDesignSpecializationField();
$common = parent::getDesignSpecializationField();
$additions .= $common['additions'];

return [
Expand Down
2 changes: 1 addition & 1 deletion inc/fields/ipfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function isPrerequisites() {
}

public function getDesignSpecializationField() {
$common = $common = parent::getDesignSpecializationField();
$common = parent::getDesignSpecializationField();
$additions = $common['additions'];

return [
Expand Down
2 changes: 1 addition & 1 deletion inc/fields/ldapselectfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function getDesignSpecializationField() {
$additions .= '<td colspan="2">&nbsp;</td>';
$additions .= '</tr>';

$common = $common = parent::getDesignSpecializationField();
$common = parent::getDesignSpecializationField();
$additions .= $common['additions'];

return [
Expand Down
1 change: 1 addition & 0 deletions inc/fields/radiosfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ public function isValid() {
}

public function isValidValue($value) {
$value = Toolbox::stripslashes_deep($value);
$value = trim($value);
return in_array($value, $this->getAvailableValues());
}
Expand Down
2 changes: 1 addition & 1 deletion inc/fields/textareafield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function getDesignSpecializationField() {
$additions .= '</td>';
$additions .= '</tr>';

$common = $common = PluginFormcreatorField::getDesignSpecializationField();
$common = PluginFormcreatorField::getDesignSpecializationField();
$additions .= $common['additions'];

return [
Expand Down
2 changes: 1 addition & 1 deletion inc/fields/textfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getDesignSpecializationField() {
$additions .= '<td></td>';
$additions .= '</tr>';

$common = $common = parent::getDesignSpecializationField();
$common = parent::getDesignSpecializationField();
$additions .= $common['additions'];

return [
Expand Down
2 changes: 1 addition & 1 deletion inc/fields/urgencyfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function getDesignSpecializationField() {
$additions .= '</td>';
$additions .= '</tr>';

$common = $common = PluginFormcreatorField::getDesignSpecializationField();
$common = PluginFormcreatorField::getDesignSpecializationField();
$additions .= $common['additions'];

return [
Expand Down
8 changes: 5 additions & 3 deletions inc/form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,10 @@ public function displayUserForm() {
}

echo '<ol>';

if (!isset($_SESSION['formcreator']['data'])) {
$_SESSION['formcreator']['data'] = [];
}
$sections = (new PluginFormcreatorSection)->getSectionsFromForm($formId);
foreach ($sections as $section) {
$sectionId = $section->getID();
Expand Down Expand Up @@ -1291,7 +1295,7 @@ public function displayUserForm() {
}
}
}
echo $question->getRenderedHtml();
echo $question->getRenderedHtml(true, $_SESSION['formcreator']['data']);
$lastQuestion = $question;
}
echo '</div>';
Expand Down Expand Up @@ -1343,8 +1347,6 @@ public function displayUserForm() {
plugin_formcreator.showFields($("form[name=\'' . $formName . '\']"));
})');

unset($_SESSION['formcreator']['data']);

// Display submit button
echo '<div class="center">';
echo Html::submit(__('Send'), ['name' => 'submit_formcreator']);
Expand Down
6 changes: 1 addition & 5 deletions inc/formanswer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1243,13 +1243,9 @@ protected function validateFormAnswer($input) {

$this->questionFields = $form->getFields();
foreach (array_keys($this->questionFields) as $id) {
$this->questionFields[$id]->parseAnswerValues($input);

// Test integrity of the value
$key = "formcreator_field_$id";
if (!isset($input[$key])) {
continue;
}
$this->questionFields[$id]->parseAnswerValues($input);
$fieldValidities[$id] = $this->questionFields[$id]->isValidValue($input[$key]);
}
// any invalid field will invalidate the answers
Expand Down
6 changes: 4 additions & 2 deletions inc/question.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,10 @@ public function getRenderedHtml($canEdit = true, $value = []) {
if (!$field->isPrerequisites()) {
return '';
}
if (isset($_SESSION['formcreator']['data'])) {
$field->parseAnswerValues($_SESSION['formcreator']['data']);

$key = 'formcreator_field_' . $this->getID();
if (isset($value[$key])) {
$field->deserializeValue($value[$key]);
} else {
$field->deserializeValue($this->fields['default_values']);
}
Expand Down
2 changes: 1 addition & 1 deletion js/scripts.js.php
Original file line number Diff line number Diff line change
Expand Up @@ -1600,4 +1600,4 @@ function plugin_formcreator_updateCompositePeerType(rand) {
$('#plugin_formcreator_link_ticket').hide();
$('#plugin_formcreator_link_target').show();
}
}
}

0 comments on commit 006b286

Please sign in to comment.