prostock
prostock

Reputation: 9545

django- how to check validity of single input field inside multi input form

I have a form with multiple input fields, but only want to use one input from the form. What is the proper way to check field validity and get cleaned data for the one field?

thanks !

Upvotes: 3

Views: 906

Answers (1)

Wolph
Wolph

Reputation: 80031

The proper way would probably be to add it to it's own form ;)

But... you can do it like this:

form = SomeForm(request.POST)
field = form.fields['your_field']
data = field.widget.value_from_datadict(form.data, form.files, form.add_prefix('your_field'))
cleaned_data = field.clean(data)

Upvotes: 3

Related Questions