Opened 9 hours ago

Last modified 7 hours ago

#36212 closed New feature

How about providing type safe access to form field data? — at Version 1

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 (1)

comment:1 by Justin Black, 9 hours ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top