MDL-55417 forms: Keep the JS for autocomplete in the template
authorDamyon Wiese <damyon@moodle.com>
Tue, 16 Aug 2016 05:24:23 +0000 (13:24 +0800)
committerDan Poltawski <dan@moodle.com>
Fri, 23 Sep 2016 09:53:30 +0000 (10:53 +0100)
Part of MDL-55071

lib/form/autocomplete.php
theme/noname/templates/core_form/element-autocomplete.mustache

index 5d695ea..876cb5e 100644 (file)
@@ -209,10 +209,6 @@ class MoodleQuickForm_autocomplete extends MoodleQuickForm_select {
         global $PAGE;
 
         $this->_generateId();
         global $PAGE;
 
         $this->_generateId();
-        $id = $this->getAttribute('id');
-        $PAGE->requires->js_call_amd('core/form-autocomplete', 'enhance', $params = array('#' . $id, $this->tags, $this->ajax,
-            $this->placeholder, $this->casesensitive, $this->showsuggestions, $this->noselectionstring));
-
         $context = parent::export_for_template($output);
         $context['tags'] = $this->tags;
         $context['ajax'] = $this->ajax;
         $context = parent::export_for_template($output);
         $context['tags'] = $this->tags;
         $context['ajax'] = $this->ajax;
index 75f93a1..de67eef 100644 (file)
             {{/element.options}}
         </select>
     {{/element}}
             {{/element.options}}
         </select>
     {{/element}}
-{{/ core_form/element-template }}
\ No newline at end of file
+{{/ core_form/element-template }}
+{{#js}}
+require(['core/form-autocomplete'], function(module) {
+    module.enhance({{#quote}}#{{element.id}}{{/quote}},
+                   {{#quote}}{{element.tags}}{{/quote}},
+                   {{#quote}}{{element.ajax}}{{/quote}},
+                   {{#quote}}{{element.placeholder}}{{/quote}},
+                   {{#quote}}{{element.casesensitive}}{{/quote}},
+                   {{#quote}}{{element.showsuggestions}}{{/quote}},
+                   {{#quote}}{{element.noselectionstring}}{{/quote}});
+});
+{{/js}}