MDL-55417 forms: Keep the JS for autocomplete in the template
[moodle.git] / theme / noname / templates / core_form / element-autocomplete.mustache
index 03ae368..de67eef 100644 (file)
@@ -1,8 +1,5 @@
-<div class="form-group row {{#error}}has-danger{{/error}}">
-    <label class="col-md-3 col-form-label" for="{{element.id}}">
-        {{{label}}} {{{helpbutton}}}
-    </label>
-    <div class="col-md-9 form-inline">
+{{< core_form/element-template }}
+    {{$element}}
         <select class="custom-select {{#error}}form-control-danger{{/error}}" name="{{element.name}}"
             id="{{element.id}}"
             {{#element.multiple}}multiple{{/element.multiple}}
             {{#error}}
                 autofocus aria-describedby="id_error_{{element.name}}"
             {{/error}}
-            {{#element.attributes}}
-                {{name}}={{#quote}}{{value}}{{/quote}} ddd
-            {{/element.attributes}}
-            >
+            {{{element.attributes}}} >
             {{#element.options}}
             <option value="{{value}}" {{#selected}}selected{{/selected}}>{{text}}</option>
             {{/element.options}}
         </select>
-        <div class="form-control-feedback" id="id_error_{{element.name}}" {{^error}} style="display: none;"{{/error}}>
-            {{{error}}}
-        </div>
-    </div>
-</div>
+    {{/element}}
+{{/ core_form/element-template }}
 {{#js}}
-require(['jquery', 'core/event'], function($, Event) {
-    var element = document.getElementById('{{element.id}}');
-    $(element).on(Event.Events.FORM_FIELD_VALIDATION, function(event, msg) {
-        event.preventDefault();
-        var parent = $(element).closest('.form-group');
-        var feedback = parent.find('.form-control-feedback');
-        if (msg !== '') {
-            parent.addClass('has-danger');
-            $(element).addClass('form-control-danger');
-            $(element).attr('aria-describedby', $(element).attr('id') + '-feedback');
-            feedback.html(msg);
-            feedback.show();
-        } else {
-            parent.removeClass('has-danger');
-            $(element).removeClass('form-control-danger');
-            $(element).attr('aria-describedby', '');
-            feedback.hide();
-        }
-    });
+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}}
\ No newline at end of file
+{{/js}}