Skip to content

Commit

Permalink
Remember input in LocalStorage fix #456
Browse files Browse the repository at this point in the history
Signed-off-by: hamza mahjoubi <hamzamahjoubi221@gmail.com>
  • Loading branch information
hamza mahjoubi authored and hamza221 committed Dec 19, 2022
1 parent a2bdfd2 commit ee6db12
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
Empty file added PHP
Empty file.
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<licence>agpl</licence>
<version>3.0.1</version>
<dependencies>
<nextcloud min-version="25" max-version="25" />
<nextcloud min-version="25" max-version="26" />
</dependencies>

<author>Affan Hussain</author>
Expand Down
2 changes: 0 additions & 2 deletions src/components/Questions/QuestionDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ export default {
props: {
dropDownState: {
type: Object,
required: false,
default: null,
},
},
Expand Down
50 changes: 37 additions & 13 deletions src/views/Submit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,26 @@ export default {
return message
},
},
mounted() {
if (localStorage.getItem('formFields')) {
this.formValuesForLocalStorage = JSON.parse(localStorage.getItem('formFields'));
this.formValuesForLocalStorage.forEach(answer => {
if (answer) {
switch (answer?.type) {
case "QuestionMultiple":
this.answers[answer.id] = answer.value;
break;
case "QuestionDate":
break;
default:
this.answers[answer.id] = [answer.value];
break;
}
}
});
}
},
watch: {
hash() {
// If public view, abort. Should normally not occur.
Expand All @@ -238,6 +258,7 @@ export default {
this.answers[answer.id] = answer.value
break
case 'QuestionDate':
this.answers[answer.id] = [answer.value]
break
default:
this.answers[answer.id] = [answer.value]
Expand Down Expand Up @@ -282,31 +303,34 @@ export default {
this.$refs.submitButton.click()
},
addFormFieldToLocalStorage(question, value, type) {
if (question.type === 'dropdown') {
for (const option in question.options) {
if (question.options[option].id === value[0]) {
this.formValuesForLocalStorage[question.id] = { id: question.id, value: question.options[option], type: type.component.name }
break
if (question.type === "dropdown") {
for (let option in question.options) {
if (question.options[option].id == value) {
this.formValuesForLocalStorage[question.id] = { id: question.id, value: question.options[option], type: type.component.name };
break;
}
}
} else {
this.formValuesForLocalStorage[question.id] = { id: question.id, value, type: type.component.name }
}
const parsed = JSON.stringify(this.formValuesForLocalStorage)
localStorage.setItem(`${this.shareHash}`, parsed)
else {
this.formValuesForLocalStorage[question.id] = { id: question.id, value, type: type.component.name };
}
const parsed = JSON.stringify(this.formValuesForLocalStorage);
localStorage.setItem('formFields', parsed);
},
deleteFormFieldFromLocalStorage() {
this.formValuesForLocalStorage = []
const parsed = JSON.stringify(this.formValuesForLocalStorage)
localStorage.setItem('formFields', parsed)
this.formValuesForLocalStorage = [];
const parsed = JSON.stringify(this.formValuesForLocalStorage);
localStorage.setItem('formFields', parsed);
},
/**
* Submit the form after the browser validated it 🚀
*/
async onSubmit() {
this.deleteFormFieldFromLocalStorage()
this.deleteFormFieldFromLocalStorage();
this.loading = true
try {
Expand Down

0 comments on commit ee6db12

Please sign in to comment.