pallets-eco / flask-admin

Simple and extensible administrative interface framework for Flask
https://flask-admin.readthedocs.io
BSD 3-Clause "New" or "Revised" License
5.73k stars 1.57k forks source link

Reload CKEditor After adding new embedded field which has CKEditor Field #1652

Open bekab95 opened 6 years ago

bekab95 commented 6 years ago

I want to reload ckeditor after adding new embedded field which has ckeditor textarea.. If I save document and open it again ckeditor will work but this is not solution, I just need reloading ckeditor js clicking on buttons for adding new fields

I googled and https://github.com/galetahub/ckeditor/issues/575#issuecomment-131583849 this solution does not work

bekab95 commented 6 years ago
<script type="text/javascript">
        $('.control-group a').click( function(e) {e.preventDefault(); 
        for(var instanceName in CKEDITOR.instances)
                CKEDITOR.remove(CKEDITOR.instances[instanceName]);        
                CKEDITOR.replaceAll('ckeditor');
         return false; } );
</script>
bekab95 commented 6 years ago

This was a solution.. I am filtering click events by control-group

bekab95 commented 6 years ago

If You Don't save and add another document unsaved document will be lost !

petrus-jvrensburg commented 5 years ago

Is this a Flask-Admin issue, or just a problem with your own javascript? I don't understand exactly what you're describing in your first post. Can you give some code for reproducing the issue?

bekab95 commented 5 years ago

@petrus-jvrensburg

class Story(Document):
    texts = ListField(EmbeddedStories)

class EmbeddedStories(EmbeddedDocument):
    position = IntField()
    image = ImageField(size=(1920, 950), thumbnail_size=(640, 316))
    text= StringField() -  **this is textarea**
    is_enabled = BooleanField()
    image_big_link = StringField()
    image_thumb_link = StringField()

So.. When I can add list of documents which has .ckeditor textarea class, after adding list item ckeditor is not creating instance for that textarea. I was trying to make new instance for newly inserted textarea, this is a bit flask admin feature with mongoengine and a bit of ckeditor..