Skip to content

Commit

Permalink
fix: Null on submissionMessage means disabled
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Aug 26, 2023
1 parent 090b65f commit cf134e5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
6 changes: 4 additions & 2 deletions lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,10 @@ public function updateForm(int $id, array $keyValuePairs): DataResponse {
}

// Create FormEntity with given Params & Id.
$form = Form::fromParams($keyValuePairs);
$form->setId($id);
foreach ($keyValuePairs as $key => $value) {
$method = 'set' . ucfirst($key);
$form->$method($value);

Check warning on line 400 in lib/Controller/ApiController.php

View check run for this annotation

Codecov / codecov/patch

lib/Controller/ApiController.php#L398-L400

Added lines #L398 - L400 were not covered by tests
}

// Update changed Columns in Db.
$this->formMapper->update($form);
Expand Down
6 changes: 3 additions & 3 deletions lib/Db/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
* @method void setShowExpiration(bool $value)
* @method integer getLastUpdated()
* @method void setLastUpdated(integer $value)
* @method string getSubmissionMessage()
* @method void setSubmissionMessage(string $value)
* @method ?string getSubmissionMessage()
* @method void setSubmissionMessage(?string $value)
*/
class Form extends Entity {
protected $hash;
Expand Down Expand Up @@ -106,7 +106,7 @@ public function read() {
'submitMultiple' => (bool)$this->getSubmitMultiple(),
'showExpiration' => (bool)$this->getShowExpiration(),
'lastUpdated' => (int)$this->getLastUpdated(),
'submissionMessage' => $this->getSubmissionMessage() ?? '',
'submissionMessage' => $this->getSubmissionMessage(),
];
}
}
2 changes: 1 addition & 1 deletion lib/Migration/Version030400Date20230628011500.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
if (!$table->hasColumn('submission_message')) {
$table->addColumn('submission_message', Types::STRING, [
'notnull' => false,
'default' => '',
'default' => null,
'length' => 2048,
'comment' => 'custom thank you message',
]);

Check warning on line 54 in lib/Migration/Version030400Date20230628011500.php

View check run for this annotation

Codecov / codecov/patch

lib/Migration/Version030400Date20230628011500.php#L48-L54

Added lines #L48 - L54 were not covered by tests
Expand Down
17 changes: 10 additions & 7 deletions src/components/SidebarTabs/SettingsSidebarTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
</div>
<NcCheckboxRadioSwitch :checked="hasCustomSubmissionMessage"
type="switch"
@update:checked="onUpdateShowSubmissionMessageInput">
@update:checked="onUpdateHasCustomSubmissionMessage">
{{ t('forms', 'Custom submission message') }}
</NcCheckboxRadioSwitch>
<div v-show="hasCustomSubmissionMessage"
Expand Down Expand Up @@ -130,7 +130,6 @@ export default {
maxStringLengths: loadState('forms', 'maxStringLengths'),
/** If custom submission message is shown as input or rendered markdown */
editMessage: false,
showSubmissionMessageInput: false,
}
},
Expand All @@ -139,7 +138,7 @@ export default {
* If the form has a custom submission message or the user wants to add one (settings switch)
*/
hasCustomSubmissionMessage() {
return !!this.form?.submissionMessage || this.showSubmissionMessageInput
return this.form?.submissionMessage !== undefined && this.form?.submissionMessage !== null
},
/**
Expand Down Expand Up @@ -218,10 +217,14 @@ export default {
this.$emit('update:formProp', 'submissionMessage', target.value)
},
onUpdateShowSubmissionMessageInput() {
this.showSubmissionMessageInput = !this.showSubmissionMessageInput
// Remove submission message if disabled
if (!this.showSubmissionMessageInput && this.form.submissionMessage) {
/**
* Enable or disable the whole custom submission message
* Disabled means the value is set to null.
*/
onUpdateHasCustomSubmissionMessage() {
if (this.hasCustomSubmissionMessage) {
this.$emit('update:formProp', 'submissionMessage', null)
} else {
this.$emit('update:formProp', 'submissionMessage', '')
}
},
Expand Down
5 changes: 2 additions & 3 deletions src/views/Submit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,11 @@
</template>
</NcEmptyContent>
<NcEmptyContent v-else-if="success || !form.canSubmit"
:title="t('forms', 'Thank you for completing the form!')"
:description="form.submissionMessage">
:title="t('forms', 'Thank you for completing the form!')">
<template #icon>
<IconCheck :size="64" />
</template>
<template v-if="form.submissionMessage" #description>
<template v-if="typeof form.submissionMessage === 'string'" #description>
<!-- eslint-disable-next-line vue/no-v-html -->
<p class="submission-message" v-html="submissionMessageHTML" />
</template>
Expand Down

0 comments on commit cf134e5

Please sign in to comment.