Creating a custom Django form field that uses two <input>s
django, django-forms, python
Solution
Have a look at the SelectDateWidget. It splits the input of a date into three select boxes.
And the doc string says:
This also serves as an example of a Widget that has more than one HTML element and hence implements `value_from_datadict`.
Problem
How can I make a Django field that renders itself as a pair of input fields? Reasoning: I am trying to write a new custom field. I will use it for a captcha-like service. The service works by requesting a question - then receiving one and a token. The validation happens by sending the answer along with the token. I want to write a form field that encapsulates this logic. The elements should render (IMO) like ``` <input type="hidden" name="_token" value="1234567890" /> <input type="text" name="answer" /> ``` And on submit I need the value of `_token` and `answer` to validate the answer.