Python django.forms.widgets.Input() Examples

The following are 11 code examples of django.forms.widgets.Input(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.forms.widgets , or try the search function .
Example #1
Source File: helper.py    From DCRM with GNU Affero General Public License v3.0 6 votes vote down vote up
def render_layout(self, form, context, template_pack=TEMPLATE_PACK):
        """
        Copy any field label to the ``placeholder`` attribute.
        Note, this method is called when :attr:`layout` is defined.
        """
        # Writing the label values into the field placeholders.
        # This is done at rendering time, so the Form.__init__() could update any labels before.
        # Django 1.11 no longer lets EmailInput or URLInput inherit from TextInput,
        # so checking for `Input` instead while excluding `HiddenInput`.
        for field in form.fields.values():
            if field.label and \
                    isinstance(field.widget, (Input, forms.Textarea)) and \
                    not isinstance(field.widget, forms.HiddenInput):
                field.widget.attrs['placeholder'] = u"{0}:".format(field.label)

        return super(CompactLabelsCommentFormHelper, self).render_layout(form, context, template_pack=template_pack) 
Example #2
Source File: forms.py    From django-cas-server with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(BootsrapForm, self).__init__(*args, **kwargs)
        for field in self.fields.values():
            # Only tweak the field if it will be displayed
            if not isinstance(field.widget, widgets.HiddenInput):
                attrs = {}
                if (
                    isinstance(field.widget, (widgets.Input, widgets.Select, widgets.Textarea)) and
                    not isinstance(field.widget, (widgets.CheckboxInput,))
                ):
                    attrs['class'] = "form-control"
                if isinstance(field.widget, (widgets.Input, widgets.Textarea)) and field.label:
                    attrs["placeholder"] = field.label
                if field.required:
                    attrs["required"] = "required"
                field.widget.attrs.update(attrs) 
Example #3
Source File: test_widget.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_no_trailing_newline_in_attrs(self):
        self.check_html(Input(), 'name', 'value', strict=True, html='<input type="None" name="name" value="value">') 
Example #4
Source File: test_widget.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_attr_false_not_rendered(self):
        html = '<input type="None" name="name" value="value">'
        self.check_html(Input(), 'name', 'value', html=html, attrs={'readonly': False}) 
Example #5
Source File: test_input.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_attrs_with_type(self):
        attrs = {'type': 'date'}
        widget = Input(attrs)
        self.check_html(widget, 'name', 'value', '<input type="date" name="name" value="value">')
        # reuse the same attrs for another widget
        self.check_html(Input(attrs), 'name', 'value', '<input type="date" name="name" value="value">')
        attrs['type'] = 'number'  # shouldn't change the widget type
        self.check_html(widget, 'name', 'value', '<input type="date" name="name" value="value">') 
Example #6
Source File: test_json.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_custom_widget_kwarg(self):
        """The widget can be overridden with a kwarg."""
        field = forms.JSONField(widget=widgets.Input)
        self.assertIsInstance(field.widget, widgets.Input) 
Example #7
Source File: test_json.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_custom_widget_attribute(self):
        """The widget can be overridden with an attribute."""
        class CustomJSONField(forms.JSONField):
            widget = widgets.Input

        field = CustomJSONField()
        self.assertIsInstance(field.widget, widgets.Input) 
Example #8
Source File: test_widget.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_attr_false_not_rendered(self):
        html = '<input type="None" name="name" value="value">'
        self.check_html(Input(), 'name', 'value', html=html, attrs={'readonly': False}) 
Example #9
Source File: test_input.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_attrs_with_type(self):
        attrs = {'type': 'date'}
        widget = Input(attrs)
        self.check_html(widget, 'name', 'value', '<input type="date" name="name" value="value">')
        # reuse the same attrs for another widget
        self.check_html(Input(attrs), 'name', 'value', '<input type="date" name="name" value="value">')
        attrs['type'] = 'number'  # shouldn't change the widget type
        self.check_html(widget, 'name', 'value', '<input type="date" name="name" value="value">') 
Example #10
Source File: test_json.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_custom_widget_kwarg(self):
        """The widget can be overridden with a kwarg."""
        field = forms.JSONField(widget=widgets.Input)
        self.assertIsInstance(field.widget, widgets.Input) 
Example #11
Source File: test_json.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_custom_widget_attribute(self):
        """The widget can be overridden with an attribute."""
        class CustomJSONField(forms.JSONField):
            widget = widgets.Input

        field = CustomJSONField()
        self.assertIsInstance(field.widget, widgets.Input)