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