def test_text_input(self): """<input type="text">""" class TextForm(forms.Form): text = forms.CharField(label='My text field') rendered = TextForm().as_p() self.assertHTMLEqual(rendered, """ <p> <label for="id_text">My text field:</label> <input class=" form-control" type="text" name="text" id="id_text" /> </p>""") form = TextForm(data={'text': ''}) self.assertFalse(form.is_valid()) form = TextForm(data={'text': 'some text'}) self.assertTrue(form.is_valid()) class TextFormNotRequire(forms.Form): text = forms.CharField(required=False) rendered = TextFormNotRequire().as_p() self.assertHTMLEqual(rendered, """ <p> <label for="id_text">Text:</label> <input class=" form-control" type="text" name="text" id="id_text"> </p>""") class TextFormAttr(forms.Form): text = forms.CharField( widget=forms.TextInput(attrs={'placeholder': 'Heheheh'}) ) rendered = TextFormAttr(initial={'text': 'some initial text'}).as_p() self.assertHTMLEqual(rendered, """ <p> <label for="id_text">Text:</label> <input class=" form-control" type="text" name="text" id="id_text" value="some initial text" placeholder="Heheheh" > </p>""") invalid = lambda: forms.CharField(max_length=5).clean('foo bar') self.assertRaises(forms.ValidationError, invalid) class TextFormMax(forms.Form): text = forms.CharField(max_length=2) self.assertFalse(TextFormMax(data={'text': 'foo'}).is_valid()) rendered = TextFormMax(data={'text': 0}).as_p() self.assertHTMLEqual(rendered, """ <p> <label for="id_text">Text:</label> <input class=" form-control" type="text" name="text" id="id_text" value="0" maxlength="2"> </p>""")
class PwFormWidget(forms.Form): text = forms.CharField() pw = forms.CharField(widget=forms.PasswordInput)
class ComboForm(forms.Form): combo = forms.ComboField(fields=[forms.EmailField(), forms.CharField(max_length=10)])
class PwForm(forms.Form): pw = forms.CharField(widget=forms.PasswordInput)
class TextFormMax(forms.Form): text = forms.CharField(max_length=2)
class TextFormAttr(forms.Form): text = forms.CharField( widget=forms.TextInput(attrs={'placeholder': 'Heheheh'}) )
class TextFormNotRequire(forms.Form): text = forms.CharField(required=False)
class TextForm(forms.Form): text = forms.CharField(label='My text field')
class SearchForm(forms.Form): query = forms.CharField(widget=forms.SearchInput)
class TextForm(forms.Form): text = forms.CharField(widget=forms.Textarea)
class TextFormAttrs(forms.Form): text = forms.CharField( widget=forms.Textarea(attrs={'rows': 42, 'cols': 55}) )
class HiddenForm(forms.Form): hide = forms.CharField(widget=forms.HiddenInput())
class PwFormData(forms.Form): text = forms.CharField() pw = forms.CharField( widget=forms.PasswordInput(render_value=True) )
class Form(forms.Form): text = forms.CharField(widget=forms.TextInput(attrs={ 'foo': True, 'bar': False, }))
class SelectFormWidget(forms.Form): foo = forms.CharField(widget=forms.Select(choices=choices), required=False)
class SelectForm(forms.Form): foo = forms.CharField(widget=forms.Select(choices=choices))