close #1552 Fixed: Text Editor value can not change

This commit is contained in:
Cüneyt Şentürk 2020-07-28 16:34:45 +03:00
parent 2c2c22958a
commit 8509b6f5ef
2 changed files with 27 additions and 12 deletions

View File

@ -49,45 +49,64 @@
let editorRef = this.$refs.editor; let editorRef = this.$refs.editor;
let node = editorRef.children[0]; let node = editorRef.children[0];
this.editor.on('text-change', () => { this.editor.on('text-change', () => {
let html = node.innerHTML let html = node.innerHTML;
if (html === '<p><br></p>') { if (html === '<p><br></p>') {
html = ''; html = '';
} }
this.content = html
this.content = html;
this.$emit('input', this.content); this.$emit('input', this.content);
}) })
}, },
pasteHTML () { pasteHTML () {
if (!this.editor) { if (!this.editor) {
return return
} }
this.editor.pasteHTML(this.value)
this.editor.pasteHTML(this.value);
}, },
randomString() { randomString() {
let text = ""; let text = "";
let possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; let possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
for (let i = 0; i < 5; i++) for (let i = 0; i < 5; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length)); text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text; return text;
} }
}, },
async mounted () { async mounted () {
let Quill = await import('quill') this.content = this.value;
Quill = Quill.default || Quill
let Quill = await import('quill');
Quill = Quill.default || Quill;
this.editorId = this.randomString(); this.editorId = this.randomString();
this.toolbarId = this.randomString(); this.toolbarId = this.randomString();
this.$nextTick(() => { this.$nextTick(() => {
this.initialize(Quill) this.initialize(Quill)
}); });
}, },
watch: { watch: {
value (newVal) { value (newVal) {
if (newVal !== this.content) { if (newVal !== this.content) {
this.pasteHTML(newVal); this.pasteHTML(newVal);
} }
},
content (newVal) {
this.$emit('input', newVal);
} }
} }
} }

View File

@ -10,12 +10,8 @@
<akaunting-html-editor <akaunting-html-editor
name="{{ $name }}" name="{{ $name }}"
@if (!empty($attributes['v-model'])) @if (!empty($value))
:value="{{ $attributes['v-model'] . ' = ' . `$value` }}" :value="{{ `$value` }}"
@elseif (!empty($attributes['data-field']))
:value="{{ 'form.' . $attributes['data-field'] . '.' . $name . ' = '. `$value` }}"
@else
:value="form.{{ $name }} = `{{ $value }}`"
@endif @endif
@if (!empty($attributes['v-model'])) @if (!empty($attributes['v-model']))