Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'setData' of undefined #167

Open
masoudline opened this issue Nov 5, 2020 · 5 comments
Open

TypeError: Cannot read property 'setData' of undefined #167

masoudline opened this issue Nov 5, 2020 · 5 comments
Labels
pending:feedback This issue is blocked by necessary feedback. type:question

Comments

@masoudline
Copy link

masoudline commented Nov 5, 2020

how can i save editorData as a prop in vuejs?
i have a laravel backend and i need send product->description as props to ckeditor
my code:
mounted() { if(this.mainData){ this.editorData = this.mainData } },
but i have these error:
[Vue warn]: Error in callback for watcher "value": "TypeError: Cannot read property 'setData' of undefined"

@FilipTokarski
Copy link
Member

Hi, thanks for the report. Could you please provide some more precise steps + code to reproduce this error? Also, does this error occur only when trying to set data taken from the server, and not with other content?

@FilipTokarski FilipTokarski added pending:feedback This issue is blocked by necessary feedback. type:question labels Nov 6, 2020
@ConnorHowell
Copy link

For anyone coming across this in future; there seems to be an issue with assigning a value to ckeditor in the 'mounted' hook.
Not 100% sure on what's causing this but it seems it's trying to assign the value before the ckeditor instance has been created; a workaround is to use the following to delay the assignment:

setTimeout(() => {
    this.editorValue = 'New Value';
}, 100);

@bizsimon
Copy link

bizsimon commented Dec 10, 2020

@ConnorHowell the setTimeout worked. thank you for saving me hours of frustrations.
however, the 100ms is a bit arbitrary for me. all we are doing is waiting for the editor instance to be ready. so moving the value assignment into the 'ready' event also did the same thing.

<ckeditor @ready="onEditorReady" v-model="editorValue"></ckeditor>

in methods

methods: {
    onEditorReady: function() { this.editorValue = 'New Value'; }
}

@ConnorHowell
Copy link

@bizsimon good point, guessing the permanent fix to this issue would be for the component to check the instance exists prior to assigning the value in the watcher for 'modelValue':

if ( newValue !== oldValue && newValue !== this.$_lastEditorData ) {
this.$_instance.setData( newValue );
}

@pomek do you want a PR for this, seems like a fairly trivial fix?

@psmyrek psmyrek self-assigned this Dec 10, 2020
@cerberos
Copy link

cerberos commented Mar 9, 2021

I have created a component that uses the CKEditor inside

<template> <ckeditor :editor="editor" v-model="editorValue" @ready="editorReady" :config="configurations" :disabled="disabled"></ckeditor> </template>

editorValue is bean updated from the watcher:
watch: { editorValue(newText) { this.$emit('input', newText) }, value(newValue){ this.editorValue = newValue } }

this was triggering the error when the component was accessed for second time so i solved it by including 2 new variables: ready and tempValue

the editorReady become:
editorReady(){ this.ready = true this.editorValue = this.tempValue }

the watcher changes to:
watch: { editorValue(newText) { this.$emit('input', newText) }, value(newValue){ if(this.ready){ this.editorValue = newValue } else { this.tempValue = newValue } } }

so instead of using a setTimeout i change the value of the ckeditor when the editor is ready. hope this will help someone

@psmyrek psmyrek removed their assignment Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending:feedback This issue is blocked by necessary feedback. type:question
Projects
None yet
Development

No branches or pull requests

6 participants