Flask-admin: Feature Request: Inline/Select hybrid

Created on 3 Dec 2013  路  6Comments  路  Source: flask-admin/flask-admin

If you don't inline a model, you can select an existing instance to associate with, but you can't create a new instance. If you do inline a model, you can create a new instance to associate with, but you can't associate with an existing instance. Am I mistaken?

It would be nice if I could get both the inlined and non-inlined version of the field at the same time, so I could associate with existing items AND create new items inline.

This could be implemented by just showing both the select field and the "Add X" button. In this case, models would only be inlined when they are being created, and they would move to the non-inlined select interface when you returned to edit the parent record.

enhancement help-wanted inline-forms

Most helpful comment

Another 6 months later, and now I need this feature, too!

From what I can make out, this shouldn't be too hard to implement. We already have the "create" modal for use when create_modal == True; we could use code similar to the one used in that case. I'm thinking something like this:

  • If enabled, the render method of that field will add a "plus" icon accompanied with a script.
  • When clicked, the script opens a modal with the related model's modals/create.html page inside
  • Form will be AJAX-submitted, or whatever usually happens for create modals
  • Instead of inserting the new record into the list as in the normal create page, it gets inserted
    into the list of select/select2 options, and also gets set as the currently selected option.

Perhaps we could also add a Gmail-style "foobar (add new)" in the select2 list like what shows eg. while setting labels in Gmail.

All 6 comments

It would be kind of cool to allow the user to dynamically choose to edit one of the child documents by clicking on an "edit" link while editing some other document. That way they could freely edit sub-documents without having to re-post the entire collection of sub-documents.

I agree, this would be a very good feature. Analog to Django, see Figure 6-13 at http://www.djangobook.com/en/2.0/chapter06.html where you have the "green plus"-feature.

Bumping almost 2 years later. That could be really useful for me. Did any of you guys come up with something?

Another 6 months later, and now I need this feature, too!

From what I can make out, this shouldn't be too hard to implement. We already have the "create" modal for use when create_modal == True; we could use code similar to the one used in that case. I'm thinking something like this:

  • If enabled, the render method of that field will add a "plus" icon accompanied with a script.
  • When clicked, the script opens a modal with the related model's modals/create.html page inside
  • Form will be AJAX-submitted, or whatever usually happens for create modals
  • Instead of inserting the new record into the list as in the normal create page, it gets inserted
    into the list of select/select2 options, and also gets set as the currently selected option.

Perhaps we could also add a Gmail-style "foobar (add new)" in the select2 list like what shows eg. while setting labels in Gmail.

@badrihippo the proposal sound great. A PR would be welcome.

@badrihippo the proposal sound great. A PR would be welcome.

I'm not working with Flask or flask-admin right now, but I'll get back when I have the time. (If anyone else wants to implement it before that, they're welcome).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pmazurek picture pmazurek  路  6Comments

macfire picture macfire  路  3Comments

nMustaki picture nMustaki  路  3Comments

timgogochen picture timgogochen  路  7Comments

fwiersENO picture fwiersENO  路  6Comments