Skip to content

Commit 776aff1

Browse files
authored
Merge pull request #350 from zoul0813/feature/347-no-empty-labels
Feature/347 no empty labels
2 parents 2999c82 + f0c2281 commit 776aff1

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/formGenerator.vue

+2
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ div.vue-form-generator(v-if='schema != null')
205205
206206
// Should field type have a label?
207207
fieldTypeHasLabel(field) {
208+
if(isNil(field.label)) return false;
209+
208210
let relevantType = "";
209211
if (field.type === "input") {
210212
relevantType = field.inputType;

test/unit/specs/VueFormGenerator.spec.js

+16-5
Original file line numberDiff line numberDiff line change
@@ -1095,20 +1095,31 @@ describe("VueFormGenerator.vue", () => {
10951095
});
10961096

10971097
it("should return true", () => {
1098-
expect(form.fieldTypeHasLabel({ type: "input", inputType: "checkbox"})).to.be.true;
1099-
expect(form.fieldTypeHasLabel({ type: "input", inputType: "text"})).to.be.true;
1100-
expect(form.fieldTypeHasLabel({ type: "checklist" })).to.be.true;
1101-
expect(form.fieldTypeHasLabel({ type: "input", inputType: "image"})).to.be.true;
1098+
expect(form.fieldTypeHasLabel({ type: "input", inputType: "checkbox", label: "checkbox"})).to.be.true;
1099+
expect(form.fieldTypeHasLabel({ type: "input", inputType: "text", label: "text"})).to.be.true;
1100+
expect(form.fieldTypeHasLabel({ type: "checklist",label: "checklist"})).to.be.true;
1101+
expect(form.fieldTypeHasLabel({ type: "input", inputType: "image", label: "image"})).to.be.true;
11021102
});
11031103

11041104
it("should return false", () => {
1105+
// with label text defined
1106+
expect(form.fieldTypeHasLabel({ type: "input", inputType: "button", label: "button"})).to.be.false;
1107+
expect(form.fieldTypeHasLabel({ type: "input", inputType: "submit", label: "submit"})).to.be.false;
1108+
expect(form.fieldTypeHasLabel({ type: "input", inputType: "reset", label: "reset"})).to.be.false;
1109+
1110+
// without label text defined
1111+
expect(form.fieldTypeHasLabel({ type: "input", inputType: "checkbox"})).to.be.false;
1112+
expect(form.fieldTypeHasLabel({ type: "input", inputType: "text"})).to.be.false;
1113+
expect(form.fieldTypeHasLabel({ type: "checklist"})).to.be.false;
1114+
expect(form.fieldTypeHasLabel({ type: "input", inputType: "image"})).to.be.false;
11051115
expect(form.fieldTypeHasLabel({ type: "input", inputType: "button"})).to.be.false;
11061116
expect(form.fieldTypeHasLabel({ type: "input", inputType: "submit"})).to.be.false;
11071117
expect(form.fieldTypeHasLabel({ type: "input", inputType: "reset"})).to.be.false;
11081118
});
11091119

11101120
it("should default to true for unknown types", () => {
1111-
expect(form.fieldTypeHasLabel({ type: "input", inputType: "unsupported-or-unknown"})).to.be.true;
1121+
expect(form.fieldTypeHasLabel({ type: "input", inputType: "unsupported-or-unknown", label:"unsupported"})).to.be.true;
1122+
expect(form.fieldTypeHasLabel({ type: "input", inputType: "unsupported-or-unknown"})).to.be.false;
11121123
});
11131124
});
11141125

0 commit comments

Comments
 (0)