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

Issue with Inlines in admin #2

Open
rchrd2 opened this issue Jan 25, 2016 · 0 comments
Open

Issue with Inlines in admin #2

rchrd2 opened this issue Jan 25, 2016 · 0 comments

Comments

@rchrd2
Copy link

rchrd2 commented Jan 25, 2016

The editor doesn't work with new inlines in the admin that are created with javascript. If you press the "Add a new row" button, the editor shows up, but it doesn't update the hidden textarea. This happens, because the html is not updated correctly. The javascript produces something like this:

</div></trix-toolbar><trix-editor input="id_aboutintrotext_set-__prefix__-text" class="trix-content" contenteditable="" trix-id="2" toolbar="trix-toolbar-2"><div><!--block-->fdssadfdsafdssassa</div></trix-editor></p>

Notice the "__prefix__" is still there.

I was able to work around this by making my own copy of static/admin/js/inlines.js and adding a few lines:

    var updateElementIndex = function(el, prefix, ndx) {
      var id_regex = new RegExp("(" + prefix + "-(\\d+|__prefix__))");
      var replacement = prefix + "-" + ndx;
      if ($(el).prop("for")) {
        $(el).prop("for", $(el).prop("for").replace(id_regex, replacement));
      }
      if (el.id) {
        el.id = el.id.replace(id_regex, replacement);
      }
      if (el.name) {
        el.name = el.name.replace(id_regex, replacement);
      }
      // @HACK(richard) needed for django trix
      if ($(el).attr('input')) {
        $(el).attr('input', $(el).attr('input').replace(id_regex, replacement));
      }
    };

I wonder if there's a way to modify the way this is implemented so it works with django's built-in javascript. If the "for" property is used instead of "input", that could make it work.

joesolly added a commit that referenced this issue Mar 15, 2017
jcarbaugh pushed a commit that referenced this issue Mar 16, 2017
* add setter to name so inline.js in django will work

connects to #2

* Update trix-core.js

* Update trix.js

* Update trix-core.js

* Update trix.js

* Update trix-core.js
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

1 participant