fields: give Page conditions access to all substitution variables (#6964)
This commit is contained in:
parent
befd0e0461
commit
9eee1104c8
|
@ -502,3 +502,26 @@ def form_password_field_submit(pub, password):
|
|||
def test_form_password_field_submit(pub):
|
||||
form_password_field_submit(pub, 'foobar')
|
||||
form_password_field_submit(pub, u'foobar\u00eb')
|
||||
|
||||
def test_form_multi_page_formdef_count_condition(pub):
|
||||
formdef = create_formdef()
|
||||
formdef.fields = [fields.PageField(id='0', label='1st page', type='page'),
|
||||
fields.StringField(id='1', label='string'),
|
||||
fields.PageField(id='2', label='2nd page', type='page',
|
||||
condition='form_objects.count > 0'),
|
||||
fields.StringField(id='3', label='string 2')]
|
||||
formdef.store()
|
||||
|
||||
resp = get_app(pub).get('/test/')
|
||||
formdef.data_class().wipe()
|
||||
resp.forms[0]['f1'] = 'foo'
|
||||
resp = resp.forms[0].submit('submit') # should go straight to validation
|
||||
assert 'Check values then click submit.' in resp.body
|
||||
|
||||
# add a formdata this will make the second page appear.
|
||||
formdef.data_class()().store()
|
||||
|
||||
resp = get_app(pub).get('/test/')
|
||||
resp.forms[0]['f1'] = 'foo'
|
||||
resp = resp.forms[0].submit('submit') # should NOT go straight to validation
|
||||
assert 'Check values then click submit.' not in resp.body
|
||||
|
|
|
@ -1117,6 +1117,7 @@ class PageField(Field):
|
|||
|
||||
from formdata import get_dict_with_varnames
|
||||
data = get_dict_with_varnames(formdef.fields, dict)
|
||||
data.update(get_publisher().substitutions.get_context_variables())
|
||||
|
||||
try:
|
||||
if eval(self.condition, get_publisher().get_global_eval_dict(), data):
|
||||
|
|
Loading…
Reference in New Issue