Fix error handling for tinymce [SCI-7127]

This commit is contained in:
Anton 2022-09-02 11:19:54 +02:00
parent 17d69131f3
commit 5f21c06b26

View file

@ -88,17 +88,12 @@
} }
}, },
characterCount() { characterCount() {
if(this.error) { if (this.editorInstance()) {
this.editorInstance.blurDisabled = true; this.editorInstance().blurDisabled = this.error != false ;
} else {
this.editorInstance.blurDisabled = false;
} }
} }
}, },
computed: { computed: {
editorInstance() {
return tinyMCE.editors[0];
},
error() { error() {
if(this.characterLimit && this.characterCount > this.characterLimit) { if(this.characterLimit && this.characterCount > this.characterLimit) {
return( return(
@ -124,11 +119,13 @@
initTinymce(e) { initTinymce(e) {
let textArea = `#${this.objectType}_textarea_${this.objectId}`; let textArea = `#${this.objectType}_textarea_${this.objectId}`;
if (this.active) return
if (e && $(e.target).hasClass('atwho-user-popover')) return if (e && $(e.target).hasClass('atwho-user-popover')) return
if (e && $(e.target).hasClass('record-info-link')) return if (e && $(e.target).hasClass('record-info-link')) return
if (e && $(e.target).parent().hasClass('atwho-inserted')) return if (e && $(e.target).parent().hasClass('atwho-inserted')) return
TinyMCE.init(textArea, (data) => { TinyMCE.init(textArea, (data) => {
if (data) { if (data) {
this.$emit('update', data) this.$emit('update', data)
} }
@ -136,27 +133,29 @@
}).then(() => { }).then(() => {
this.active = true; this.active = true;
this.initCharacterCount(); this.initCharacterCount();
this.$emit('editingEnabled');
}); });
this.$emit('editingEnabled')
}, },
getStaticUrl(name) { getStaticUrl(name) {
return $(`meta[name=\'${name}\']`).attr('content'); return $(`meta[name=\'${name}\']`).attr('content');
}, },
initCharacterCount() { initCharacterCount() {
if (!this.editorInstance) return; if (!this.editorInstance()) return;
this.characterCount = $(this.editorInstance.getContent()).text().length this.characterCount = $(this.editorInstance().getContent()).text().length;
this.editorInstance().on('input change paste keydown', (e) => {
this.editorInstance.on('input change paste keydown', (e) => {
e.currentTarget && (this.characterCount = (e.currentTarget).innerText.length); e.currentTarget && (this.characterCount = (e.currentTarget).innerText.length);
}); });
this.editorInstance.on('remove', () => this.active = false) this.editorInstance().on('remove', () => this.active = false);
// clear error on cancel // clear error on cancel
$(this.editorInstance.container).find('.tinymce-cancel-button').on('click', ()=> { $(this.editorInstance().container).find('.tinymce-cancel-button').on('click', ()=> {
this.characterCount = 0; this.characterCount = 0;
}); });
},
editorInstance() {
return tinyMCE.editors[0];
} }
} }
} }