mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-62848 form: Fix missing support for {{#js}} helper in autocomplete
The form-autocomplete module uses three Mustache templates core/form_autocomplete_input, core/form_autocomplete_suggestions and core/form_autocomplete_selection. However, it did not support executing the JS that is eventually part of those templates.
This commit is contained in:
parent
175b3708c9
commit
5cdf8d49c7
2 changed files with 20 additions and 4 deletions
2
lib/amd/build/form-autocomplete.min.js
vendored
2
lib/amd/build/form-autocomplete.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -882,9 +882,23 @@ define(['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification']
|
||||||
context.options = suggestions;
|
context.options = suggestions;
|
||||||
context.items = [];
|
context.items = [];
|
||||||
|
|
||||||
var renderInput = templates.render('core/form_autocomplete_input', context);
|
// Collect rendered inline JS to be executed once the HTML is shown.
|
||||||
var renderDatalist = templates.render('core/form_autocomplete_suggestions', context);
|
var collectedjs = '';
|
||||||
var renderSelection = templates.render('core/form_autocomplete_selection', context);
|
|
||||||
|
var renderInput = templates.render('core/form_autocomplete_input', context).then(function(html, js) {
|
||||||
|
collectedjs += js;
|
||||||
|
return html;
|
||||||
|
});
|
||||||
|
|
||||||
|
var renderDatalist = templates.render('core/form_autocomplete_suggestions', context).then(function(html, js) {
|
||||||
|
collectedjs += js;
|
||||||
|
return html;
|
||||||
|
});
|
||||||
|
|
||||||
|
var renderSelection = templates.render('core/form_autocomplete_selection', context).then(function(html, js) {
|
||||||
|
collectedjs += js;
|
||||||
|
return html;
|
||||||
|
});
|
||||||
|
|
||||||
return $.when(renderInput, renderDatalist, renderSelection).then(function(input, suggestions, selection) {
|
return $.when(renderInput, renderDatalist, renderSelection).then(function(input, suggestions, selection) {
|
||||||
originalSelect.hide();
|
originalSelect.hide();
|
||||||
|
@ -892,6 +906,8 @@ define(['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification']
|
||||||
originalSelect.after(input);
|
originalSelect.after(input);
|
||||||
originalSelect.after(selection);
|
originalSelect.after(selection);
|
||||||
|
|
||||||
|
templates.runTemplateJS(collectedjs);
|
||||||
|
|
||||||
// Update the form label to point to the text input.
|
// Update the form label to point to the text input.
|
||||||
originalLabel.attr('for', state.inputId);
|
originalLabel.attr('for', state.inputId);
|
||||||
// Add the event handlers.
|
// Add the event handlers.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue