darklow / django-suit-redactor

Imperavi Readactor (WYSIWYG editor) integration app for Django admin
26 stars 21 forks source link

Reactor in new inline row required fail #7

Open engrost opened 10 years ago

engrost commented 10 years ago

Django 1.6.2 django-suit 0.2.4-0.2.9 django-suit-reactor 0.2

Scenario: 2 Models - parent and FK with SortableStackedInline in admin and reactor widget over field

class PageInline(SortableTabularInline):
    model = Page
    extra = 0
    fields = ('name','description','order')
    sortable = 'order'

    def formfield_for_dbfield(self, db_field, **kwargs):
        if db_field.name == 'description':
            kwargs['widget'] = RedactorWidget(editor_options={'lang': 'en'})
        return super(PageInline,self).formfield_for_dbfield(db_field,**kwargs)

How to recreate:

Expected: Save without any problems

Actual: Getting error that 'description' is empty

Work Around:

  1. after first save you can fill in description and save without problems
  2. remove widget
bigjust commented 7 years ago

This is still an issue, and a rather glaring one

I'll investigate since this is an open bug with our integration, but any insight from the authors would be much appreciated

mordonez-me commented 7 years ago

The following code is a simple workaround for this situation:

$(function () {
        Suit.after_inline.register('my_unique_func_name', function(inline_prefix, row){
            $.each($(row).find('.redactor_box'), function(index, redactor_box){
                var script = $(redactor_box).parent().find("script").html()
                if(script.search("__prefix__") > -1){
                    $(redactor_box).find(".redactor_editor").remove()
                    $(redactor_box).find(".redactor_toolbar").remove()
                    $(redactor_box).removeClass("redactor_box")
                    var index = $(row).closest('.inline-related').index(".dynamic-" + inline_prefix)
                    eval(script.replace("__prefix__", index))
                }    
            })

        });
    });