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

Editor does not show content on init #344

Closed
retzion opened this issue Jun 3, 2016 · 17 comments
Closed

Editor does not show content on init #344

retzion opened this issue Jun 3, 2016 · 17 comments
Labels

Comments

@retzion
Copy link

retzion commented Jun 3, 2016

My text area is populated with data via php..

<textarea id="submission_content" maxlength="5000" name="content" placeholder="Content goes here" required>{{ $submission->content }}</textarea>

I init the editor like this..

var submissionContent = new SimpleMDE({ element: $("#submission_content")[0], hideIcons: ["image", "heading"], spellChecker: false, placeholder: "10 to 5000 characters" })

When the page loads the editor looks empty of content. However, when you focus into the editor the content appears.

@prostoandrei
Copy link

@retzion
You need do this.

setTimeout(function() {
  simplemde.codemirror.refresh();
}.bind(simplemde), 0);

This is not a simplemde-markdown-editor problem.

@retzion
Copy link
Author

retzion commented Jun 6, 2016

Works great. Thanks.

@retzion retzion closed this as completed Jun 6, 2016
@prostoandrei
Copy link

But i think need add default refresh codemirror on initialization same way

@WesCossick
Copy link
Member

@prostoandrei Would you mind submitting a PR that does this? It wouldn't hurt and it'd fix this strange bug for everyone.

@WesCossick
Copy link
Member

Nevermind, this will be fixed in the next release.

@WesCossick WesCossick mentioned this issue Jun 8, 2016
@prostoandrei
Copy link

@WesCossick ok. I will be glad to help in the future.

@Polsaker
Copy link

This is still happening to me. Using 1.11.2 and the content only loads when I click the editor.

@WesCossick
Copy link
Member

@Polsaker please submit a new issue for this and reproduce the error using JSFiddle.

@retzion
Copy link
Author

retzion commented Aug 9, 2016

I take it back.. This worked only on desktop browsers..
setTimeout(function() { simplemde.codemirror.refresh(); }.bind(simplemde), 0);

On mobile devices, however, the issue still persists. When a view is loaded the editor is blank (even though there is content inside it). When I focus into the editor, the content is revealed.

I have updated to ver 1.11.2

@retzion retzion reopened this Aug 9, 2016
@WesCossick
Copy link
Member

What mobile devices are you using?

@WesCossick WesCossick added the bug label Aug 9, 2016
@retzion
Copy link
Author

retzion commented Aug 9, 2016

False alarm. The only browser having an issue is Chrome's mobile emulator (not a real device). I believe I had the old script cached or something. I also removed the following method and it all works fine now. Thank you.

setTimeout(function() { submissionBackground.codemirror.refresh() }.bind(submissionBackground), 0)

@retzion retzion closed this as completed Aug 9, 2016
@retzion
Copy link
Author

retzion commented Aug 10, 2016

got this from our QA..

On Android, the entered text is sill not appearing until I click into the field. On iOS, the entered text appears if I scroll down the page.

@gazpachu
Copy link

@prostoandrei your fix is not working for me in a React app where the textarea is being updated by local state:

<textarea className="input-field" id="editor" ref="editor" value={this.state.selectedItem.content} onChange={(event) => this.updateItem(event, 'content')}></textarea>

@akash-mitra
Copy link

This issue is still persisting. I can confirm after checking on version 1.6.2 with Chrome Version 58.0.3029.96 (64-bit) on Mac

@LukaSikic
Copy link

Issue is still there on latest version of SimpleMDE on Chrome 58.0.3029.110 (64-bit) - Windows 10

@jacklinwood
Copy link

jacklinwood commented Nov 9, 2020

I have multiple instances on one page and need an initialValue on all of them.

I have read multiple threads including this one and have come up with the following code:

const simplemde = {};

$('textarea').each(function(key, element) {
    simplemde[element.id] = new SimpleMDE({
        element: element,
        toolbar: ['bold', 'italic', 'link'],
        spellChecker: false,
        initialValue: 'Test'
    });
});

Object.values(simplemde).forEach((value) => {
    setTimeout(function() {
        value.codemirror.refresh();
    }.bind(value), 0);
});

But this does not work for me. It still only shows the initialValue for the first instance and the others need to be clicked to show the value.

Any ideas?

@ccadek
Copy link

ccadek commented Nov 17, 2020

@jacklinwood I also ran into the exact same issue though I do not store my editors in a single array. I fixed my problem by increasing the timeout to 200 milliseconds.

Code of my solution:

setTimeout(function() {    
	simplemde.codemirror.refresh();  
}, 200);

I am not too familiar with JS internals so I am not sure if setting the timeout to 200 milliseconds will fix your issue as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

9 participants