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

Django 3.0, admin inlines, throws JS error when new inline formset is added #97

Open
jturmel opened this issue Aug 6, 2020 · 2 comments

Comments

@jturmel
Copy link

jturmel commented Aug 6, 2020

Screen Shot 2020-08-06 at 11 42 35 AM

@jturmel
Copy link
Author

jturmel commented Aug 6, 2020

Screen Shot 2020-08-06 at 11 46 58 AM

@StevenMapes
Copy link

StevenMapes commented Nov 5, 2021

I overload the froala-django.js file within my projects with this version that fixes the issue. The problem is the invalid called to jQuery along with the javascript on the page not allowing inline formsets to generate the editors as the prefix is not being replace in the cloned script tag. This fixes that

function getCookie(name) {
  var cookieValue = null;
  if (document.cookie && document.cookie != '') {
    var cookies = document.cookie.split(';');
    for (var i = 0; i < cookies.length; i++) {
      var cookie = cookies[i].trim();
      // Does this cookie string begin with the name we want?
      if (cookie.substring(0, name.length + 1) == (name + '=')) {
        cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
        break;
      }
    }
  }
  return cookieValue;
}

if (typeof django !== 'undefined' && typeof django.jQuery !== 'undefined') {
  (function ($) {
    $(document).on('formset:added', function (event, $row, formsetName) {
      $row.find('textarea').each(function () {
        var parts = this.closest('tr').id.split('-');
        var froala_script = this.nextElementSibling.innerText.replace('__prefix__', parts[parts.length-1]);
        froala_script = froala_script.replace("\n","");
        this.parentElement.innerHTML = this.outerHTML;

        var additional_script = document.createElement("script");
        additional_script.textContent = froala_script;
        document.head.appendChild((additional_script));
      });
    });
  })(django.jQuery);
}

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

No branches or pull requests

2 participants