django-suit-redactor icon indicating copy to clipboard operation
django-suit-redactor copied to clipboard

Reactor in new inline row required fail

Open engrost opened this issue 11 years ago • 2 comments

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:

  • adding new inline in admin
  • fill 'description' into reactor widget
  • click save

Expected: Save without any problems

Actual: Getting error that 'description' is empty

  • looking at HTTP POST - the text value for description field is empty too.

Work Around:

  1. after first save you can fill in description and save without problems
  2. remove widget

engrost avatar Sep 01 '14 13:09 engrost

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

bigjust avatar Oct 26 '16 13:10 bigjust

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))
                }    
            })
            
        });
    });

mordonez-me avatar Sep 17 '17 18:09 mordonez-me