Tuesday, July 19, 2016

configuring a custom widget subclass based on user entered data

Hi,

I am trying to create a custom widget that is a subclass of MultiWidget that creates a variable number of widgets based on previous user input. Which means I can't fully configure the widget in the form class. A simplified description of what I am trying to accomplish is to have one form that asks for a start date and an end date, then have the next form include this custom MultiWidget, which would use those two dates to create a CheckboxInput for each day in that range of dates.

I intend to build a table that looks like a calendar to put these widgets in, so I can't just do this with a for loop in the template.

The documentation I have seen for a subclass of a MultiWidget shows a hard coded tuple of widgets being created, but not a variable number. And I have seen how a Form subclass can supply arguments to a widget, but I don't see how the form class can get data from previous user input. For that I would need to be able to configure the widget from within the view function. Can I get access to the custom MultiWidget after the form creates it, and can I change the set of widgets in the MultiWidget after it has already been constructed (but before it has been rendered)?

David

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/E1869C12-DEBE-44A5-9D27-4933C1FAFB56%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment