forms: do not consider fields from other pages for live sources (#68197)
This commit is contained in:
parent
ac98b726d0
commit
3385a003d0
|
@ -101,6 +101,32 @@ def test_field_live_condition(pub):
|
|||
assert '<span class="label">Foo</span>' in resp.text
|
||||
|
||||
|
||||
def test_field_live_condition_on_other_page(pub):
|
||||
FormDef.wipe()
|
||||
formdef = FormDef()
|
||||
formdef.name = 'Foo'
|
||||
formdef.fields = [
|
||||
fields.PageField(type='page', id='0', label='Page1'),
|
||||
fields.StringField(type='string', id='1', label='Bar', size='40', required=True, varname='bar'),
|
||||
fields.PageField(type='page', id='2', label='Page2'),
|
||||
fields.StringField(
|
||||
type='string',
|
||||
id='3',
|
||||
label='Foo',
|
||||
size='40',
|
||||
required=True,
|
||||
varname='foo',
|
||||
condition={'type': 'django', 'value': 'form_var_bar == "bye"'},
|
||||
),
|
||||
]
|
||||
formdef.store()
|
||||
|
||||
app = get_app(pub)
|
||||
resp = app.get(formdef.get_url())
|
||||
assert 'f1' in resp.form.fields
|
||||
assert 'data-live-source' not in resp.html.find('div', {'data-field-id': '1'}).attrs
|
||||
|
||||
|
||||
def test_field_live_items_condition(pub):
|
||||
FormDef.wipe()
|
||||
formdef = FormDef()
|
||||
|
|
|
@ -967,7 +967,13 @@ class FormDef(StorableObject):
|
|||
def set_live_condition_sources(self, form, fields):
|
||||
live_condition_fields = {}
|
||||
|
||||
fields_ids = {str(x.id) for x in fields}
|
||||
|
||||
for field in self.iter_fields(include_block_fields=True):
|
||||
if (hasattr(field, 'block_field') and str(field.block_field.id) not in fields_ids) or (
|
||||
not hasattr(field, 'block_field') and str(field.id) not in fields_ids
|
||||
):
|
||||
continue
|
||||
if field.condition:
|
||||
field.varnames = field.get_condition_varnames(formdef=self)
|
||||
for varname in field.varnames:
|
||||
|
|
Loading…
Reference in New Issue