Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIO-8199: Fixes an issue where Checkbox does not have id and for attributes #5581

Merged
merged 7 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/components/checkbox/Checkbox.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@ describe('Checkbox Component', () => {
});
});

it('Span should have correct text label', () => {
it('Span should have correct text label and attributes', () => {
return Harness.testCreate(CheckBoxComponent, comp1).then((component) => {
const checkboxes = component.element.querySelectorAll('input[ref="input"]');
assert.equal(checkboxes.length, 1);
const componentClass = checkboxes[0].getAttribute('class');
const componentId = checkboxes[0].getAttribute('id');
assert(componentClass.indexOf('form-check-input') !== -1, 'No form-check-input class.');
assert(componentId, 'Should provide "id" attribute for the input');
const labels = component.element.querySelectorAll('label');
assert.equal(labels.length, 1);
assert(labels[0].getAttribute('class').indexOf('form-check-label') !== -1, 'No form-check-label class');
assert.equal(labels[0].getAttribute('for'), componentId, 'Should provide a proper "for" attribute for the' +
' label');
const spans = labels[0].querySelectorAll('span');
assert.equal(spans.length, 1);
assert.equal(spans[0].innerHTML, 'Check me');
Expand Down
8 changes: 7 additions & 1 deletion src/templates/bootstrap/checkbox/form.ejs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<div class="form-check checkbox">
<label class="{{ctx.input.labelClass}} form-check-label">
<label
class="{{ctx.input.labelClass}} form-check-label"
for="{{ctx.instance.id}}-{{ctx.component.key}}"
id="l-{{ctx.instance.id}}-{{ctx.component.key}}"
>
<{{ctx.input.type}}
ref="input"
{% for (var attr in ctx.input.attr) { %}
{{attr}}="{{ctx.input.attr[attr]}}"
{% } %}
id="{{ctx.instance.id}}-{{ctx.component.key}}"
{% if (ctx.checked) { %}checked=true{% } %}
aria-required="{{ctx.component.validate.required}}"
aria-labelledby="l-{{ctx.instance.id}}-{{ctx.component.key}}"
{% if (ctx.component.description) { %}
aria-describedby="d-{{ctx.instance.id}}-{{ctx.component.key}}"
{% } %}
Expand Down
4 changes: 2 additions & 2 deletions test/renders/component-bootstrap-checkbox-multiple.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div id="checkbox" class="form-group has-feedback formio-component formio-component-checkbox formio-component-checkbox formio-component-multiple " ref="component">
<div class="form-check checkbox">
<label class=" form-check-label">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" value="0" aria-required="false">
<label class=" form-check-label" for="checkbox-checkbox" id="l-checkbox-checkbox">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" value="0" id="checkbox-checkbox" aria-required="false" aria-labelledby="l-checkbox-checkbox">
<span>Checkbox</span>
</input>
</label>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div id="checkbox" class="form-group has-feedback formio-component formio-component-checkbox formio-component-checkbox " ref="component">
<div class="form-check checkbox">
<label class=" form-check-label">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" disabled="disabled" value="0" aria-required="false">
<label class=" form-check-label" for="checkbox-checkbox" id="l-checkbox-checkbox">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" disabled="disabled" value="0" id="checkbox-checkbox" aria-required="false" aria-labelledby="l-checkbox-checkbox">
<span>Checkbox</span>
</input>
</label>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div id="checkbox" class="form-group has-feedback formio-component formio-component-checkbox formio-component-checkbox " ref="component">
<div class="form-check checkbox">
<label class=" form-check-label">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" disabled="disabled" value="0" checked=true aria-required="false">
<label class=" form-check-label" for="checkbox-checkbox" id="l-checkbox-checkbox">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" disabled="disabled" value="0" id="checkbox-checkbox" checked=true aria-required="false" aria-labelledby="l-checkbox-checkbox">
<span>Checkbox</span>
</input>
</label>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div id="checkbox" class="form-group has-feedback formio-component formio-component-checkbox formio-component-checkbox " ref="component">
<div class="form-check checkbox">
<label class=" form-check-label">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" disabled="disabled" value="0" aria-required="false">
<label class=" form-check-label" for="checkbox-checkbox" id="l-checkbox-checkbox">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" disabled="disabled" value="0" id="checkbox-checkbox" aria-required="false" aria-labelledby="l-checkbox-checkbox">
<span>Checkbox</span>
</input>
</label>
Expand Down
4 changes: 2 additions & 2 deletions test/renders/component-bootstrap-checkbox-readOnly.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div id="checkbox" class="form-group has-feedback formio-component formio-component-checkbox formio-component-checkbox " ref="component">
<div class="form-check checkbox">
<label class=" form-check-label">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" disabled="disabled" value="0" aria-required="false">
<label class=" form-check-label" for="checkbox-checkbox" id="l-checkbox-checkbox">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" disabled="disabled" value="0" id="checkbox-checkbox" aria-required="false" aria-labelledby="l-checkbox-checkbox">
<span>Checkbox</span>
</input>
</label>
Expand Down
4 changes: 2 additions & 2 deletions test/renders/component-bootstrap-checkbox-required.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div id="checkbox" class="form-group has-feedback formio-component formio-component-checkbox formio-component-checkbox required" ref="component">
<div class="form-check checkbox">
<label class=" field-required form-check-label">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" value="0" aria-required="true">
<label class=" field-required form-check-label" for="checkbox-checkbox" id="l-checkbox-checkbox">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" value="0" id="checkbox-checkbox" aria-required="true" aria-labelledby="l-checkbox-checkbox">
<span>Checkbox</span>
</input>
</label>
Expand Down
4 changes: 2 additions & 2 deletions test/renders/component-bootstrap-checkbox.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div id="checkbox" class="form-group has-feedback formio-component formio-component-checkbox formio-component-checkbox " ref="component">
<div class="form-check checkbox">
<label class=" form-check-label">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" value="0" aria-required="false">
<label class=" form-check-label" for="checkbox-checkbox" id="l-checkbox-checkbox">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" value="0" id="checkbox-checkbox" aria-required="false" aria-labelledby="l-checkbox-checkbox">
<span>Checkbox</span>
</input>
</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</label>
<div ref="element">
<div class="input-group">
<input ref="input" name="data[dateTime]" type="text" class="form-control" lang="en" disabled="disabled" value="2019-11-06 06:00 PM" id="dateTime-dateTime" aria-labelledby="l-dateTime-dateTime " aria-required="false"></input>
<input ref="input" name="data[dateTime]" type="text" class="form-control" lang="en" disabled="disabled" value="2019-11-06 08:00 PM" id="dateTime-dateTime" aria-labelledby="l-dateTime-dateTime " aria-required="false"></input>
<span aria-live="assertive" id="dateTime-liveRegion" class="sr-only" ref="liveRegion"></span>
<div class="input-group-append" ref="suffix">
<span class="input-group-text">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</label>
<div ref="element">
<div class="input-group">
<input ref="input" name="data[dateTime]" type="text" class="form-control" lang="en" disabled="disabled" value="2019-11-25 08:11 PM" id="dateTime-dateTime" aria-labelledby="l-dateTime-dateTime " aria-required="false"></input>
<input ref="input" name="data[dateTime]" type="text" class="form-control" lang="en" disabled="disabled" value="2019-11-25 10:11 PM" id="dateTime-dateTime" aria-labelledby="l-dateTime-dateTime " aria-required="false"></input>
<span aria-live="assertive" id="dateTime-liveRegion" class="sr-only" ref="liveRegion"></span>
<div class="input-group-append" ref="suffix">
<span class="input-group-text">
Expand Down
4 changes: 2 additions & 2 deletions test/renders/component-bootstrap3-checkbox-multiple.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div id="checkbox" class="form-group has-feedback formio-component formio-component-checkbox formio-component-checkbox formio-component-multiple " ref="component">
<div class="form-check checkbox">
<label class=" form-check-label">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" value="0" aria-required="false">
<label class=" form-check-label" for="checkbox-checkbox" id="l-checkbox-checkbox">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" value="0" id="checkbox-checkbox" aria-required="false" aria-labelledby="l-checkbox-checkbox">
<span>Checkbox</span>
</input>
</label>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div id="checkbox" class="form-group has-feedback formio-component formio-component-checkbox formio-component-checkbox " ref="component">
<div class="form-check checkbox">
<label class=" form-check-label">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" disabled="disabled" value="0" aria-required="false">
<label class=" form-check-label" for="checkbox-checkbox" id="l-checkbox-checkbox">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" disabled="disabled" value="0" id="checkbox-checkbox" aria-required="false" aria-labelledby="l-checkbox-checkbox">
<span>Checkbox</span>
</input>
</label>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div id="checkbox" class="form-group has-feedback formio-component formio-component-checkbox formio-component-checkbox " ref="component">
<div class="form-check checkbox">
<label class=" form-check-label">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" disabled="disabled" value="0" checked=true aria-required="false">
<label class=" form-check-label" for="checkbox-checkbox" id="l-checkbox-checkbox">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" disabled="disabled" value="0" id="checkbox-checkbox" checked=true aria-required="false" aria-labelledby="l-checkbox-checkbox">
<span>Checkbox</span>
</input>
</label>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div id="checkbox" class="form-group has-feedback formio-component formio-component-checkbox formio-component-checkbox " ref="component">
<div class="form-check checkbox">
<label class=" form-check-label">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" disabled="disabled" value="0" aria-required="false">
<label class=" form-check-label" for="checkbox-checkbox" id="l-checkbox-checkbox">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" disabled="disabled" value="0" id="checkbox-checkbox" aria-required="false" aria-labelledby="l-checkbox-checkbox">
<span>Checkbox</span>
</input>
</label>
Expand Down
4 changes: 2 additions & 2 deletions test/renders/component-bootstrap3-checkbox-readOnly.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div id="checkbox" class="form-group has-feedback formio-component formio-component-checkbox formio-component-checkbox " ref="component">
<div class="form-check checkbox">
<label class=" form-check-label">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" disabled="disabled" value="0" aria-required="false">
<label class=" form-check-label" for="checkbox-checkbox" id="l-checkbox-checkbox">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" disabled="disabled" value="0" id="checkbox-checkbox" aria-required="false" aria-labelledby="l-checkbox-checkbox">
<span>Checkbox</span>
</input>
</label>
Expand Down
4 changes: 2 additions & 2 deletions test/renders/component-bootstrap3-checkbox-required.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div id="checkbox" class="form-group has-feedback formio-component formio-component-checkbox formio-component-checkbox required" ref="component">
<div class="form-check checkbox">
<label class=" field-required form-check-label">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" value="0" aria-required="true">
<label class=" field-required form-check-label" for="checkbox-checkbox" id="l-checkbox-checkbox">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" value="0" id="checkbox-checkbox" aria-required="true" aria-labelledby="l-checkbox-checkbox">
<span>Checkbox</span>
</input>
</label>
Expand Down
4 changes: 2 additions & 2 deletions test/renders/component-bootstrap3-checkbox.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div id="checkbox" class="form-group has-feedback formio-component formio-component-checkbox formio-component-checkbox " ref="component">
<div class="form-check checkbox">
<label class=" form-check-label">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" value="0" aria-required="false">
<label class=" form-check-label" for="checkbox-checkbox" id="l-checkbox-checkbox">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" value="0" id="checkbox-checkbox" aria-required="false" aria-labelledby="l-checkbox-checkbox">
<span>Checkbox</span>
</input>
</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</label>
<div ref="element">
<div class="input-group">
<input ref="input" name="data[dateTime]" type="text" class="form-control" lang="en" disabled="disabled" value="2019-11-06 06:00 PM" id="dateTime-dateTime"></input>
<input ref="input" name="data[dateTime]" type="text" class="form-control" lang="en" disabled="disabled" value="2019-11-06 08:00 PM" id="dateTime-dateTime"></input>
<div class="input-group-addon" ref="suffix">
<i ref="icon" class="fa fa-calendar" style=""></i>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</label>
<div ref="element">
<div class="input-group">
<input ref="input" name="data[dateTime]" type="text" class="form-control" lang="en" disabled="disabled" value="2019-11-25 08:11 PM" id="dateTime-dateTime"></input>
<input ref="input" name="data[dateTime]" type="text" class="form-control" lang="en" disabled="disabled" value="2019-11-25 10:11 PM" id="dateTime-dateTime"></input>
<div class="input-group-addon" ref="suffix">
<i ref="icon" class="fa fa-calendar" style=""></i>
</div>
Expand Down
4 changes: 2 additions & 2 deletions test/renders/component-bootstrap5-checkbox-multiple.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div id="checkbox" class="formio-form-group has-feedback formio-component formio-component-checkbox formio-component-checkbox formio-component-multiple " ref="component">
<div class="form-check checkbox">
<label class=" form-check-label">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" value="0" aria-required="false">
<label class=" form-check-label" for="checkbox-checkbox" id="l-checkbox-checkbox">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" value="0" id="checkbox-checkbox" aria-required="false" aria-labelledby="l-checkbox-checkbox">
<span>Checkbox</span>
</input>
</label>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div id="checkbox" class="formio-form-group has-feedback formio-component formio-component-checkbox formio-component-checkbox " ref="component">
<div class="form-check checkbox">
<label class=" form-check-label">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" disabled="disabled" value="0" aria-required="false">
<label class=" form-check-label" for="checkbox-checkbox" id="l-checkbox-checkbox">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" disabled="disabled" value="0" id="checkbox-checkbox" aria-required="false" aria-labelledby="l-checkbox-checkbox">
<span>Checkbox</span>
</input>
</label>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div id="checkbox" class="formio-form-group has-feedback formio-component formio-component-checkbox formio-component-checkbox " ref="component">
<div class="form-check checkbox">
<label class=" form-check-label">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" disabled="disabled" value="0" checked=true aria-required="false">
<label class=" form-check-label" for="checkbox-checkbox" id="l-checkbox-checkbox">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" disabled="disabled" value="0" id="checkbox-checkbox" checked=true aria-required="false" aria-labelledby="l-checkbox-checkbox">
<span>Checkbox</span>
</input>
</label>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div id="checkbox" class="formio-form-group has-feedback formio-component formio-component-checkbox formio-component-checkbox " ref="component">
<div class="form-check checkbox">
<label class=" form-check-label">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" disabled="disabled" value="0" aria-required="false">
<label class=" form-check-label" for="checkbox-checkbox" id="l-checkbox-checkbox">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" disabled="disabled" value="0" id="checkbox-checkbox" aria-required="false" aria-labelledby="l-checkbox-checkbox">
<span>Checkbox</span>
</input>
</label>
Expand Down
4 changes: 2 additions & 2 deletions test/renders/component-bootstrap5-checkbox-readOnly.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div id="checkbox" class="formio-form-group has-feedback formio-component formio-component-checkbox formio-component-checkbox " ref="component">
<div class="form-check checkbox">
<label class=" form-check-label">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" disabled="disabled" value="0" aria-required="false">
<label class=" form-check-label" for="checkbox-checkbox" id="l-checkbox-checkbox">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" disabled="disabled" value="0" id="checkbox-checkbox" aria-required="false" aria-labelledby="l-checkbox-checkbox">
<span>Checkbox</span>
</input>
</label>
Expand Down
4 changes: 2 additions & 2 deletions test/renders/component-bootstrap5-checkbox-required.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div id="checkbox" class="formio-form-group has-feedback formio-component formio-component-checkbox formio-component-checkbox required" ref="component">
<div class="form-check checkbox">
<label class=" field-required form-check-label">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" value="0" aria-required="true">
<label class=" field-required form-check-label" for="checkbox-checkbox" id="l-checkbox-checkbox">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" value="0" id="checkbox-checkbox" aria-required="true" aria-labelledby="l-checkbox-checkbox">
<span>Checkbox</span>
</input>
</label>
Expand Down
4 changes: 2 additions & 2 deletions test/renders/component-bootstrap5-checkbox.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div id="checkbox" class="formio-form-group has-feedback formio-component formio-component-checkbox formio-component-checkbox " ref="component">
<div class="form-check checkbox">
<label class=" form-check-label">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" value="0" aria-required="false">
<label class=" form-check-label" for="checkbox-checkbox" id="l-checkbox-checkbox">
<input ref="input" name="data[checkbox]" type="checkbox" class="form-check-input" lang="en" value="0" id="checkbox-checkbox" aria-required="false" aria-labelledby="l-checkbox-checkbox">
<span>Checkbox</span>
</input>
</label>
Expand Down