fields: allow none prefill in items fields (#67843)
gitea-wip/wcs/pipeline/head Build started...
Details
gitea-wip/wcs/pipeline/head Build started...
Details
This commit is contained in:
parent
dd79662c1b
commit
4050ddd838
|
@ -3753,6 +3753,30 @@ def test_form_page_template_prefill_items_field(pub):
|
|||
assert logged_error.summary == 'Invalid value for items prefill on field "items"'
|
||||
pub.loggederror_class.wipe()
|
||||
|
||||
# check with a "none" explicit prefill, or a None value
|
||||
for none_prefill_value in [
|
||||
{},
|
||||
{'type': 'none'},
|
||||
{'type': 'string', 'value': '{{ None }}'},
|
||||
{'type': 'formula', 'value': 'None'},
|
||||
]:
|
||||
formdef.fields[0] = fields.ItemsField(
|
||||
id='0',
|
||||
varname='items',
|
||||
label='items',
|
||||
data_source=ds,
|
||||
display_disabled_items=True,
|
||||
prefill=none_prefill_value,
|
||||
)
|
||||
formdef.store()
|
||||
|
||||
# all checkboxes will be left unchecked
|
||||
resp = get_app(pub).get('/test/')
|
||||
assert not resp.form['f0$elementfoo'].checked
|
||||
assert not resp.form['f0$elementbar'].checked
|
||||
assert not resp.form['f0$elementbaz'].checked
|
||||
assert pub.loggederror_class.count() == 0
|
||||
|
||||
|
||||
def test_form_page_changing_prefill(pub):
|
||||
formdef = create_formdef()
|
||||
|
|
|
@ -2570,7 +2570,9 @@ class ItemsField(WidgetField, ItemFieldMixin):
|
|||
|
||||
def get_prefill_value(self, user=None, force_string=True):
|
||||
value, explicit_lock = super().get_prefill_value(user=user, force_string=False)
|
||||
if not isinstance(value, (str, tuple, list)) or not all(isinstance(x, (int, str)) for x in value):
|
||||
if value is not None and (
|
||||
not isinstance(value, (str, tuple, list)) or not all(isinstance(x, (int, str)) for x in value)
|
||||
):
|
||||
get_publisher().record_error(
|
||||
_('Invalid value for items prefill on field "%s"') % self.label,
|
||||
formdef=getattr(self, 'formdef', None),
|
||||
|
|
Loading…
Reference in New Issue