Revert "forms: refill item fields based on prefilled values (#40190)"

This reverts commit f274d4442e.
This commit is contained in:
Thomas NOËL 2020-02-27 15:36:55 +01:00
parent 55e849ff39
commit 4a13391bdb
3 changed files with 4 additions and 51 deletions

View File

@ -6887,33 +6887,6 @@ def test_field_live_select_content_on_workflow_form(pub, http_requests):
assert formdata.workflow_data['xxx_var_foo'] == 'b'
def test_field_live_select_content_based_on_prefill(pub, http_requests):
FormDef.wipe()
formdef = FormDef()
formdef.name = 'Foo'
formdef.fields = [
fields.StringField(type='string', id='1', label='Bar', size='40',
required=True, varname='bar',
prefill={'type': 'string', 'value': 'HELLO WORLD'}),
fields.ItemField(type='item', id='2', label='Foo',
data_source={
'type': 'json',
'value': '{% if form_var_bar %}http://remote.example.net/json-list?plop={{form_var_bar}}{% endif %}'
}),
]
formdef.store()
formdef.data_class().wipe()
app = get_app(pub)
resp = app.get('/foo/')
assert 'f1' in resp.form.fields
assert 'f2' in resp.form.fields
assert resp.html.find('div', {'data-field-id': '1'}).attrs['data-live-source'] == 'true'
assert resp.html.find('div', {'data-field-id': '2'}).find('select')
assert resp.html.find('option', {'value': 'a'})
assert http_requests.get_last('url') == 'http://remote.example.net/json-list?plop=HELLO WORLD'
def test_field_live_comment_content(pub, http_requests):
FormDef.wipe()
formdef = FormDef()

View File

@ -703,7 +703,6 @@ class FormDef(StorableObject):
widget = form.get_widget('f%s' % field.id)
if widget:
widget.live_condition_source = True
widget.live_condition_fields = live_condition_fields[field.varname]
def get_field_data(self, field, widget):
d = {}

View File

@ -341,13 +341,13 @@ class FormPage(Directory, FormTemplateMixin):
if self.pages.index(page) > 0:
form.add_submit('previous', _('Previous'))
had_prefill = False
if page_change:
# on page change, we fake a GET request so the form is not altered
# with errors from the previous submit; if the page was already
# visited, we restore values; otherwise we set req.form as empty.
req = get_request()
req.environ['REQUEST_METHOD'] = 'GET'
one = False
for field in displayed_fields:
k = field.id
v = None
@ -397,15 +397,12 @@ class FormPage(Directory, FormTemplateMixin):
req.form['f%s$latlng' % k] = v
else:
req.form['f%s' % k] = v
had_prefill = True
one = True
if had_prefill:
# include prefilled data
transient_formdata = self.get_transient_formdata()
transient_formdata.data.update(self.formdef.get_data(form))
else:
if not one:
req.form = {}
live_condition_fields = {}
for field in displayed_fields:
if field.prefill:
# always set additional attributes as they will be used for
@ -414,22 +411,6 @@ class FormPage(Directory, FormTemplateMixin):
self.formdef.set_live_condition_sources(form, displayed_fields)
if had_prefill:
# pass over prefilled fields that are used as live source of item
# fields
fields_to_update = set()
for field in displayed_fields:
widget = form.get_widget('f%s' % field.id)
if getattr(widget, 'prefilled', False) and getattr(widget, 'live_condition_source', False):
fields_to_update.update(widget.live_condition_fields)
elif field in fields_to_update and field.type == 'item':
kwargs = {}
with get_publisher().substitutions.temporary_feed(
transient_formdata, force_mode='lazy'):
field.perform_more_widget_changes(form, kwargs)
widget.options = kwargs['options']
widget.options_with_attributes = kwargs['options_with_attributes']
self.html_top(self.formdef.name)
form.add_hidden('step', '0')