forms: only update item options if there are new values (#40216)

This commit is contained in:
Frédéric Péters 2020-02-27 09:04:51 +01:00
parent f274d4442e
commit 407098ea38
2 changed files with 19 additions and 2 deletions

View File

@ -6913,6 +6913,22 @@ def test_field_live_select_content_based_on_prefill(pub, http_requests):
assert resp.html.find('option', {'value': 'a'})
assert http_requests.get_last('url') == 'http://remote.example.net/json-list?plop=HELLO WORLD'
# check with autocomplete and a remote source with id
NamedDataSource.wipe()
data_source = NamedDataSource(name='foobar')
data_source.data_source = {'type': 'json', 'value': 'http://remote.example.net/json?plop={{form_var_bar}}'}
data_source.query_parameter = 'q'
data_source.id_parameter = 'id'
data_source.store()
formdef.fields[1].display_mode = 'autocomplete'
formdef.fields[1].data_source['type'] = 'foobar'
formdef.store()
app = get_app(pub)
resp = app.get('/foo/')
assert 'f1' in resp.form.fields
assert 'f2' in resp.form.fields
def test_field_live_comment_content(pub, http_requests):
FormDef.wipe()

View File

@ -427,8 +427,9 @@ class FormPage(Directory, FormTemplateMixin):
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']
if 'options' in kwargs and 'options_with_attributes' in kwargs:
widget.options = kwargs['options']
widget.options_with_attributes = kwargs['options_with_attributes']
self.html_top(self.formdef.name)