Make radio select work w/ new checkboxes/radios

The visual appearance of radio and checkbox form inputs changed in
GOV.UK Elements here:

https://github.com/alphagov/govuk_elements/pull/296

This was subsequently reimplemented with different markup and no
Javascript here:
https://github.com/alphagov/govuk_elements/pull/406

This has meant making the following changes to our app:
- changing the markup in our radio/checkbox macros to match the example
  markup given by GOV.UK Elements
- removing the previous Javascript file because it’s no longer needed to
  make the radios appear visual selected
- making the buttons on the scheduled job picker look like links,
  because the grey button style looked weird with the new radio buttons
This commit is contained in:
Chris Hill-Scott
2016-12-19 10:36:17 +00:00
parent 31d03acc11
commit a592898eff
7 changed files with 91 additions and 81 deletions

View File

@@ -5,54 +5,57 @@
let states = {
'initial': Hogan.compile(`
<div class="radio-select-column">
<label class="block-label js-block-label" for="{{name}}-0">
<input checked="checked" id="{{name}}-0" name="{{name}}" type="radio" value=""> Now
</label>
<div class="multiple-choice js-multiple-choice">
<input checked="checked" id="{{name}}-0" name="{{name}}" type="radio" value="">
<label class="block-label js-block-label" for="{{name}}-0">Now</label>
</div>
</div>
<div class="radio-select-column">
{{#categories}}
<input type='button' class='button tertiary-button js-category-button' value='{{.}}' />
<input type='button' class='js-category-button' value='{{.}}' />
{{/categories}}
</div>
`),
'choose': Hogan.compile(`
<div class="radio-select-column">
<label class="block-label js-block-label" for="{{name}}-0">
<input checked="checked" id="{{name}}-0" name="{{name}}" type="radio" value="" class="js-initial-option"> Now
</label>
<div class="multiple-choice js-multiple-choice js-initial-option">
<input checked="checked" id="{{name}}-0" name="{{name}}" type="radio" value="">
<label for="{{name}}-0">Now</label>
</div>
</div>
<div class="radio-select-column">
{{#choices}}
<label class="block-label js-block-label" for="{{id}}">
<input type="radio" value="{{value}}" id="{{id}}" name="{{name}}" class="js-option" />
{{label}}
</label>
<div class="multiple-choice js-multiple-choice js-option">
<input type="radio" value="{{value}}" id="{{id}}" name="{{name}}" />
<label for="{{id}}">{{label}}</label>
</div>
{{/choices}}
</div>
`),
'chosen': Hogan.compile(`
<div class="radio-select-column">
<label class="block-label js-block-label" for="{{name}}-0">
<input id="{{name}}-0" name="{{name}}" type="radio" value="" class="js-initial-option"> Now
</label>
<div class="multiple-choice js-multiple-choice js-initial-option">
<input id="{{name}}-0" name="{{name}}" type="radio" value="">
<label for="{{name}}-0">Now</label>
</div>
</div>
<div class="radio-select-column">
{{#choices}}
<label class="block-label js-block-label" for="{{id}}">
<div class="multiple-choice js-multiple-choice">
<input checked="checked" type="radio" value="{{value}}" id="{{id}}" name="{{name}}" />
{{label}}
</label>
<label for="{{id}}">{{label}}</label>
</div>
{{/choices}}
</div>
<div class="radio-select-column">
<input type='button' class='button tertiary-button js-reset-button' value='Choose a different time' />
<input type='button' class='category-link js-reset-button' value='Choose a different time' />
</div>
`)
};
let focusSelected = function() {
setTimeout(
() => $('[type=radio]:checked').parent('label').blur().trigger('focus').addClass('selected'),
() => $('[type=radio]:checked').next('label').blur().trigger('focus').addClass('selected'),
10
);
};
@@ -62,13 +65,16 @@
this.start = function(component) {
let $component = $(component);
let render = (state, data) => $component.html(states[state].render(data));
let render = (state, data) => {
$component.html(states[state].render(data));
new GOVUK.SelectionButtons('.block-label input');
};
let choices = $('label', $component).toArray().map(function(element) {
let $element = $(element);
return {
'id': $element.attr('for'),
'label': $.trim($element.text()),
'value': $element.find('input').attr('value')
'value': $element.prev('input').attr('value')
};
});
let categories = $component.data('categories').split(',');
@@ -95,7 +101,7 @@
if (!event.pageX) return true;
event.preventDefault();
let value = $(this).attr('value');
let value = $('input', this).attr('value');
render('chosen', {
'choices': choices.filter(
element => element.value == value