forms: add support for live change of JSON data source (#31492)

This commit is contained in:
Frédéric Péters 2019-04-04 14:45:00 +02:00
parent 065247ae13
commit 3bf61b16b3
2 changed files with 15 additions and 2 deletions

View File

@ -766,7 +766,9 @@ class FormPage(Directory, FormTemplateMixin):
return self.removedraft()
form_data = session.get_by_magictoken(magictoken, {})
data = self.formdef.get_data(form)
with get_publisher().substitutions.temporary_feed(
transient_formdata, force_mode='lazy'):
data = self.formdef.get_data(form)
form_data.update(data)
if self.has_draft_support() and form.get_submit() == 'savedraft':
@ -809,7 +811,9 @@ class FormPage(Directory, FormTemplateMixin):
page_error_messages=page_error_messages)
form_data = session.get_by_magictoken(magictoken, {})
data = self.formdef.get_data(form)
with get_publisher().substitutions.temporary_feed(
transient_formdata, force_mode='lazy'):
data = self.formdef.get_data(form)
form_data.update(data)
session.add_magictoken(magictoken, form_data)
@ -1097,6 +1101,11 @@ class FormPage(Directory, FormTemplateMixin):
continue
varnames = re.findall(r'\bform[_\.]var[_\.]([a-zA-Z0-9_]+?)(?:_raw|\b)',
data_source.data_source.get('value'))
if (modified_field_varname is None or modified_field_varname in varnames) and (
field.display_mode == 'autocomplete' and data_source.query_parameter):
# computed earlier, in perform_more_widget_changes, when the field
# was added to the form
result[field.id]['source_url'] = field.url
if modified_field_varname in varnames:
result[field.id]['items'] = [
{'id': x[2], 'text': x[1]} for x in field.get_options(mode='lazy')]

View File

@ -115,6 +115,10 @@ $(function() {
var $widget = $('[data-field-id="' + key + '"]');
$widget.html(value.content);
}
if (value.source_url) {
// json change of URL
$widget.find('[data-select2-url]').data('select2-url', value.source_url);
}
});
}
});