mirror of https://github.com/django/django.git
Fixed #27161 -- Fixed form validation when an ArrayField's base_field has choices.
This commit is contained in:
parent
de9294727c
commit
9dd2443942
|
@ -27,6 +27,10 @@ class SimpleArrayField(forms.CharField):
|
|||
self.max_length = max_length
|
||||
self.validators.append(ArrayMaxLengthValidator(int(max_length)))
|
||||
|
||||
def clean(self, value):
|
||||
value = super().clean(value)
|
||||
return [self.base_field.clean(val) for val in value]
|
||||
|
||||
def prepare_value(self, value):
|
||||
if isinstance(value, list):
|
||||
return self.delimiter.join(str(self.base_field.prepare_value(v)) for v in value)
|
||||
|
|
|
@ -686,6 +686,11 @@ class TestSimpleFormField(PostgreSQLTestCase):
|
|||
self.assertIsInstance(form_field, SimpleArrayField)
|
||||
self.assertEqual(form_field.max_length, 4)
|
||||
|
||||
def test_model_field_choices(self):
|
||||
model_field = ArrayField(models.IntegerField(choices=((1, 'A'), (2, 'B'))))
|
||||
form_field = model_field.formfield()
|
||||
self.assertEqual(form_field.clean('1,2'), [1, 2])
|
||||
|
||||
def test_already_converted_value(self):
|
||||
field = SimpleArrayField(forms.CharField())
|
||||
vals = ['a', 'b', 'c']
|
||||
|
|
Loading…
Reference in New Issue