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-8461: Fixes checkbox with radio input type not present in submission on 5.x renderer #5670

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/checkbox/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export default class CheckBoxComponent extends Field {
}

get emptyValue() {
return this.component.inputType === 'radio' ? null : false;
return this.component.inputType === 'radio' ? '' : false;
}

isEmpty(value = this.dataValue) {
Expand Down
31 changes: 30 additions & 1 deletion src/components/checkbox/Checkbox.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
comp2,
comp3,
comp4,
comp5
comp5,
comp6
} from './fixtures';

describe('Checkbox Component', () => {
Expand Down Expand Up @@ -64,6 +65,34 @@ describe('Checkbox Component', () => {
});
});

it('Should be able to submit default checkbox data with the radio input type', (done) => {
const form = _.cloneDeep(comp6);
const element = document.createElement('div');
const inputName = form.components[0].name;

Formio.createForm(element, form).then(form => {
const submit = form.getComponent('submit');
const clickEvent = new Event('click');
const submitBtn = submit.refs.button;
submitBtn.dispatchEvent(clickEvent);

setTimeout(() => {
assert.equal(form.submission.data[inputName], '');
const radioCheckBox = form.getComponent('checkbox');
const radio = Harness.testElements(radioCheckBox, 'input[type="radio"]', 1)[0];
Harness.clickElement(radioCheckBox, radio);
setTimeout(() => {
assert.equal(form.submission.data[inputName], 'ok');
Harness.clickElement(radioCheckBox, radio);
setTimeout(() => {
assert.equal(form.submission.data[inputName], '');
done();
}, 200);
}, 200);
}, 200);
}).catch((err) => done(err));
});

it('Should render red asterisk for preview template of the modal required checkbox ', (done) => {
Harness.testCreate(CheckBoxComponent, comp3).then((component) => {
const label = component.element.querySelector('.control-label');
Expand Down
30 changes: 30 additions & 0 deletions src/components/checkbox/fixtures/comp6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export default
{
name: 'ckeckbox',
path: 'ckeckbox',
type: 'form',
display: 'form',

components: [
{
label: 'Checkbox',
inputType: 'radio',
tableView: false,
defaultValue: false,
key: 'checkbox',
type: 'checkbox',
name: 'some name',
value: 'ok',
input: true,
'some name': false
},
{
type: 'button',
label: 'Submit',
key: 'submit',
disableOnInvalid: true,
input: true,
tableView: false
}
],
};
3 changes: 2 additions & 1 deletion src/components/checkbox/fixtures/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import comp2 from './comp2';
import comp3 from './comp3';
import comp4 from './comp4';
import comp5 from './comp5';
export { comp1, comp2, comp3, comp4, comp5, customDefaultComponent };
import comp6 from './comp6';
export { comp1, comp2, comp3, comp4, comp5, comp6, customDefaultComponent };
6 changes: 2 additions & 4 deletions src/components/textfield/TextField.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -808,8 +808,7 @@ describe('TextField Component', () => {

const testMask = async (mask, valid) => {
const values = valid ? mask.valueValid : mask.valueInvalid;
for (let i = 0; i < values.length; i++) {
const value = values[i];
for (const value of values) {
const element = document.createElement('div');
const instance = await Formio.createForm(element, form);
instance.setPristine(false);
Expand Down Expand Up @@ -838,8 +837,7 @@ describe('TextField Component', () => {
}
};

for (let i = 0; i < masks.length; i++) {
const mask = masks[i];
for (const mask of masks) {
await testMask(mask, true);
await testMask(mask, false);
}
Expand Down
Loading