Opened 3 hours ago

Closed 45 minutes ago

#36212 closed New feature (wontfix)

How about providing type safe access to form field data?

Reported by: Justin Black Owned by:
Component: Forms Version: 5.1
Severity: Normal Keywords: form, field
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Justin Black)

Right now only cleaned data is acessed in a dict in python.
This means that type hcecking code does not know the type of that dict unless it is described as a typeddict.
How about providing type safe access to form field data?

class FormOptions(forms.Form):
    prompt = forms.CharField(widget=forms.Textarea)
    n = forms.IntegerField(min_value=1, max_value=10, initial=1)

form_options = FormOptions({'prompt': 'a', 'n': 2})

one could access it as:
form_options.prompt.cleaned_data
or
form_options.prompt

This would allow code to access type safe values for a form in python.

Change History (2)

comment:1 by Justin Black, 3 hours ago

Description: modified (diff)

comment:2 by Sarah Boyce, 45 minutes ago

Component: UncategorizedForms
Resolution: wontfix
Status: newclosed
Type: UncategorizedNew feature

As this is requesting a new feature for Django. The recommended path forward is to first propose and discuss the idea with the community and gain consensus. To do that, please consider starting a new conversation on the Django Forum, where you'll reach a broader audience and receive additional feedback.

I'll close the ticket for now, but if the community agrees with the proposal, please return to this ticket and reference the forum discussion so we can re-open it. For more information, please refer to the documented guidelines for requesting features.

I also recommend you look for similar type conversations and try to incorporate or summarize opinions from these.

Note: See TracTickets for help on using tickets.
Back to Top