pattern in data for ContributionForm

This commit is contained in:
ogerly 2022-10-14 13:00:57 +02:00
parent 68e24a5973
commit 85804a1cfa
3 changed files with 19 additions and 8 deletions

View File

@ -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

View File

@ -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

View File

@ -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