MDL-55417 forms: Clean up form element template patch
[moodle.git] / theme / noname / templates / core_form / element-template.mustache
CommitLineData
344321e1
DW
1<div class="form-group row {{#error}}has-danger{{/error}}">
2 <label class="col-md-3 col-form-label {{#element.hiddenlabel}}sr-only{{/element.hiddenlabel}}" for="{{element.id}}">
3 {{{label}}} {{{helpbutton}}}
4 </label>
5 <div class="col-md-9 form-inline">
6 {{$ element }}
7 <!-- Element goes here -->
8 {{/ element }}
9 <div class="form-control-feedback" id="id_error_{{element.name}}" {{^error}} style="display: none;"{{/error}}>
10 {{{error}}}
11 </div>
12 </div>
13</div>
14{{#js}}
15require(['jquery', 'core/event'], function($, Event) {
16 var element = document.getElementById('{{element.id}}');
17 $(element).on(Event.Events.FORM_FIELD_VALIDATION, function(event, msg) {
18 event.preventDefault();
19 var parent = $(element).closest('.form-group');
20 var feedback = parent.find('.form-control-feedback');
21 if (msg !== '') {
22 parent.addClass('has-danger');
23 $(element).addClass('form-control-danger');
24 $(element).attr('aria-describedby', $(element).attr('id') + '-feedback');
25 feedback.html(msg);
26 feedback.show();
27 } else {
28 parent.removeClass('has-danger');
29 $(element).removeClass('form-control-danger');
30 $(element).attr('aria-describedby', '');
31 feedback.hide();
32 }
33 });
34});
35{{/js}}