diff --git a/src/components/AChat/AChatForm.vue b/src/components/AChat/AChatForm.vue index 90f165236..3d3baa78e 100644 --- a/src/components/AChat/AChatForm.vue +++ b/src/components/AChat/AChatForm.vue @@ -54,9 +54,16 @@ export default { showDivider: { type: Boolean, default: false + }, + /** + * Message validator. + */ + validator: { + type: Function, + required: true } }, - emits: ['message', 'esc'], + emits: ['message', 'esc', 'error'], data: () => ({ message: '' }), @@ -118,8 +125,14 @@ export default { }, methods: { submitMessage() { - this.$emit('message', this.message) - this.message = '' + const error = this.validator(this.message) + if (error === false) { + this.$emit('message', this.message) + this.message = '' + } else { + this.$emit('error', error) + } + // Fix textarea height to 1 row after miltiline message send this.calculateInputHeight() this.focus() diff --git a/src/components/Chat/Chat.vue b/src/components/Chat/Chat.vue index c0de6af1c..75c150f36 100644 --- a/src/components/Chat/Chat.vue +++ b/src/components/Chat/Chat.vue @@ -208,7 +208,9 @@ :label="chatFormLabel" :message-text="$route.query.messageText" @message="onMessage" + @error="onMessageError" @esc="replyMessageId = -1" + :validator="messageValidator.bind(this)" >