Fixed #26283 -- Fixed removal of trailing nulls for SplitArrayField.
This commit is contained in:
parent
ab8af342b1
commit
91f87b8f91
|
@ -183,7 +183,7 @@ class SplitArrayField(forms.Field):
|
||||||
null_index = i
|
null_index = i
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
if null_index:
|
if null_index is not None:
|
||||||
cleaned_data = cleaned_data[:null_index]
|
cleaned_data = cleaned_data[:null_index]
|
||||||
errors = errors[:null_index]
|
errors = errors[:null_index]
|
||||||
errors = list(filter(None, errors))
|
errors = list(filter(None, errors))
|
||||||
|
|
|
@ -663,6 +663,20 @@ class TestSplitFormField(PostgreSQLTestCase):
|
||||||
self.assertTrue(form.is_valid(), form.errors)
|
self.assertTrue(form.is_valid(), form.errors)
|
||||||
self.assertEqual(form.cleaned_data, {'array': ['a', '', 'b']})
|
self.assertEqual(form.cleaned_data, {'array': ['a', '', 'b']})
|
||||||
|
|
||||||
|
def test_remove_trailing_nulls_not_required(self):
|
||||||
|
class SplitForm(forms.Form):
|
||||||
|
array = SplitArrayField(
|
||||||
|
forms.CharField(required=False),
|
||||||
|
size=2,
|
||||||
|
remove_trailing_nulls=True,
|
||||||
|
required=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
data = {'array_0': '', 'array_1': ''}
|
||||||
|
form = SplitForm(data)
|
||||||
|
self.assertTrue(form.is_valid())
|
||||||
|
self.assertEqual(form.cleaned_data, {'array': []})
|
||||||
|
|
||||||
def test_required_field(self):
|
def test_required_field(self):
|
||||||
class SplitForm(forms.Form):
|
class SplitForm(forms.Form):
|
||||||
array = SplitArrayField(forms.CharField(), size=3)
|
array = SplitArrayField(forms.CharField(), size=3)
|
||||||
|
|
Loading…
Reference in New Issue