diff --git a/admin/src/components/ContributionMessages/ContributionMessagesFormular.vue b/admin/src/components/ContributionMessages/ContributionMessagesFormular.vue index 695ae5109..8abe55d22 100644 --- a/admin/src/components/ContributionMessages/ContributionMessagesFormular.vue +++ b/admin/src/components/ContributionMessages/ContributionMessagesFormular.vue @@ -36,7 +36,7 @@ export default { data() { return { form: { - text: '', + text: '' }, } }, @@ -47,7 +47,7 @@ export default { mutation: adminCreateContributionMessage, variables: { contributionId: this.contributionId, - message: this.form.text.replace(/(<([^>]+)>)/gi, ''), + message: this.clearTextFromHtml, }, }) .then((result) => { @@ -65,6 +65,9 @@ export default { }, }, computed: { + clearTextFromHtml(){ + return this.form.text.replace(/(<([^>]+)>)/gi, '') + }, disabled() { if (this.form.text !== '') { return false diff --git a/frontend/src/components/ContributionMessages/ContributionMessagesFormular.vue b/frontend/src/components/ContributionMessages/ContributionMessagesFormular.vue index c2af2a04f..63a3ca47d 100644 --- a/frontend/src/components/ContributionMessages/ContributionMessagesFormular.vue +++ b/frontend/src/components/ContributionMessages/ContributionMessagesFormular.vue @@ -36,7 +36,7 @@ export default { data() { return { form: { - text: '', + text: '' }, } }, @@ -47,7 +47,7 @@ export default { mutation: createContributionMessage, variables: { contributionId: this.contributionId, - message: this.form.text.replace(/(<([^>]+)>)/gi, ''), + message: this.clearTextFromHtml, }, }) .then((result) => { @@ -65,6 +65,9 @@ export default { }, }, computed: { + clearTextFromHtml(){ + return this.form.text.replace(/(<([^>]+)>)/gi, '') + }, disabled() { if (this.form.text !== '') { return false diff --git a/frontend/src/components/Contributions/ContributionForm.vue b/frontend/src/components/Contributions/ContributionForm.vue index ea170a5d6..347ec9d9a 100644 --- a/frontend/src/components/Contributions/ContributionForm.vue +++ b/frontend/src/components/Contributions/ContributionForm.vue @@ -98,17 +98,19 @@ export default { minlength: 5, maxlength: 255, maximalDate: new Date(), - form: this.value, // includes 'id' + form: this.value, // includes 'id', + patternStripHtml: new RegExp(/(<([^>]+)>)/gi), + patternNonDigit: new RegExp(/\D/g) } }, methods: { numberFormat(value) { - return value.replace(/\D/g, '') + return value.replace(this.patternNonDigit, '') }, submit() { - this.form.amount = this.numberFormat(this.form.amount) + this.form.amount = this.form.amount.replace(this.patternNonDigit, '') // spreading is needed for testing - this.form.memo = this.form.memo.replace(/(<([^>]+)>)/gi, '') + this.form.memo = this.memoStripHtml this.$emit(this.form.id ? 'update-contribution' : 'set-contribution', { ...this.form }) this.reset() }, @@ -128,6 +130,9 @@ export default { }, }, computed: { + memoStripHtml() { + return this.form.memo.replace(this.patternStripHtml) + }, minimalDate() { // sets the date to the 1st of the previous month let date = new Date(this.maximalDate) // has to be a new object, because of 'setMonth' changes the objects date