MDL-55417 forms: Clean up form element template patch
[moodle.git] / theme / noname / templates / core_form / element-radio-inline.mustache
CommitLineData
344321e1
DW
1<label class="form-check-inline {{#error}}has-danger{{/error}}">
2<input type="radio" name="{{element.name}}"
3 id="{{element.id}}" value="{{element.value}}" size="{{element.size}}"
4 {{#element.frozen}}readonly disabled{{/element.frozen}}
5 {{#error}}
6 autofocus aria-describedby="id_error_{{element.name}}"
7 {{/error}}
8 {{{element.attributes}}} >
9 {{{label}}} {{{helpbutton}}}
10</label>
11<span class="form-control-feedback" id="id_error_{{element.name}}" {{^error}} style="display: none;"{{/error}}>
12 {{{error}}}
13</span>
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).attr('aria-describedby', $(element).attr('id') + '-feedback');
24 feedback.html(msg);
25 feedback.show();
26 } else {
27 parent.removeClass('has-danger');
28 $(element).attr('aria-describedby', '');
29 feedback.hide();
30 }
31 });
32});
33{{/js}}