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