Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a custom Django form field that uses two <input>s

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.

like image 624
Emil Ivanov Avatar asked Mar 05 '10 12:03

Emil Ivanov


1 Answers

I think you're looking for the MultiWidget, you can simply give it 2 regular widgets and it will render the combination.

like image 129
Wolph Avatar answered Nov 02 '22 23:11

Wolph