mirror of
https://github.com/django/django.git
synced 2025-08-01 17:42:56 +00:00
Fixed #26748 -- Allowed overriding JSONField's widget with an attribute.
This commit is contained in:
parent
57eb17b8c7
commit
f2c0eb19e9
2 changed files with 20 additions and 5 deletions
|
@ -3,7 +3,7 @@ import unittest
|
|||
|
||||
from django.core import exceptions, serializers
|
||||
from django.db import connection
|
||||
from django.forms import CharField, Form
|
||||
from django.forms import CharField, Form, widgets
|
||||
from django.test import TestCase
|
||||
from django.utils.html import escape
|
||||
|
||||
|
@ -291,3 +291,21 @@ class TestFormField(PostgreSQLTestCase):
|
|||
form = JsonForm({'name': 'xy', 'jfield': '{"foo"}'})
|
||||
# Appears once in the textarea and once in the error message
|
||||
self.assertEqual(form.as_p().count(escape('{"foo"}')), 2)
|
||||
|
||||
def test_widget(self):
|
||||
"""The default widget of a JSONField is a Textarea."""
|
||||
field = forms.JSONField()
|
||||
self.assertIsInstance(field.widget, widgets.Textarea)
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue