Code

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#9547 closed (invalid)

Need better support for dynamic forms

Reported by: Jonathan.Oomph@… Owned by: nobody
Component: Forms Version: 1.0
Severity: Keywords: dynamic forms
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

When creating a static form, the Forms support in django works great. However, when trying to create a dynamic form (i.e. a survey is a good example), it seems very difficult. It would be nice if I could create a Form instance and add fields at runtime. Of course, validations and handling the postback would need to work also for dynamic forms. Thanks!

Attachments (0)

Change History (3)

comment:1 Changed 5 years ago by brosner

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

Are you actually proposing a specific fix? This is already possible. Django's forms are just Python classes. You can easily create runtime classes using Python's type function. I would recommend reading up on how Python works in that respect.

type("MyForm", (forms.Form,), {"base_fields": { ... },})

base_fields is where your runtime fields are created. I am marking this as invalid. I would consider proposing an actual fix or improvement to django-developers before opening a drive by ticket. Thanks :)

comment:2 Changed 5 years ago by brosner

Oh, I just realized my code above as a bug. It should be forms.BaseForm and not forms.Form :)

comment:3 Changed 5 years ago by Jonathan.Oomph@…

Thanks for the comment. I wasn't sure the best place to share my opinion, so I apologize if I posted it in the wrong place. I am not familiar with dynamic classes in Python, but that sounds interesting. In my research of django, I found many forums with django users that were confused about dynamic forms. Some claimed it was impossible. So that's why I decided to contact the "experts". =) Thanks again.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.