#36212: How about providing type safe access to form field data?
-------------------------------+--------------------------------------
     Reporter:  Justin Black   |                    Owner:  (none)
         Type:  Uncategorized  |                   Status:  new
    Component:  Uncategorized  |                  Version:  5.1
     Severity:  Normal         |               Resolution:
     Keywords:  form, field    |             Triage Stage:  Unreviewed
    Has patch:  0              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+--------------------------------------
Description changed by Justin Black:

Old description:

> 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.

New description:

 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.

--
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36212#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019536936ab7-c96f690e-218f-4af5-aaf1-ae1ed6223d11-000000%40eu-central-1.amazonses.com.

Reply via email to