diff --git a/src/formGenerator.vue b/src/formGenerator.vue index c72cf97d..cfc79fc6 100644 --- a/src/formGenerator.vue +++ b/src/formGenerator.vue @@ -205,6 +205,8 @@ div.vue-form-generator(v-if='schema != null') // Should field type have a label? fieldTypeHasLabel(field) { + if(isNil(field.label)) return false; + let relevantType = ""; if (field.type === "input") { relevantType = field.inputType; diff --git a/test/unit/specs/VueFormGenerator.spec.js b/test/unit/specs/VueFormGenerator.spec.js index 4d0f630c..60aaa606 100644 --- a/test/unit/specs/VueFormGenerator.spec.js +++ b/test/unit/specs/VueFormGenerator.spec.js @@ -1095,20 +1095,31 @@ describe("VueFormGenerator.vue", () => { }); it("should return true", () => { - expect(form.fieldTypeHasLabel({ type: "input", inputType: "checkbox"})).to.be.true; - expect(form.fieldTypeHasLabel({ type: "input", inputType: "text"})).to.be.true; - expect(form.fieldTypeHasLabel({ type: "checklist" })).to.be.true; - expect(form.fieldTypeHasLabel({ type: "input", inputType: "image"})).to.be.true; + expect(form.fieldTypeHasLabel({ type: "input", inputType: "checkbox", label: "checkbox"})).to.be.true; + expect(form.fieldTypeHasLabel({ type: "input", inputType: "text", label: "text"})).to.be.true; + expect(form.fieldTypeHasLabel({ type: "checklist",label: "checklist"})).to.be.true; + expect(form.fieldTypeHasLabel({ type: "input", inputType: "image", label: "image"})).to.be.true; }); it("should return false", () => { + // with label text defined + expect(form.fieldTypeHasLabel({ type: "input", inputType: "button", label: "button"})).to.be.false; + expect(form.fieldTypeHasLabel({ type: "input", inputType: "submit", label: "submit"})).to.be.false; + expect(form.fieldTypeHasLabel({ type: "input", inputType: "reset", label: "reset"})).to.be.false; + + // without label text defined + expect(form.fieldTypeHasLabel({ type: "input", inputType: "checkbox"})).to.be.false; + expect(form.fieldTypeHasLabel({ type: "input", inputType: "text"})).to.be.false; + expect(form.fieldTypeHasLabel({ type: "checklist"})).to.be.false; + expect(form.fieldTypeHasLabel({ type: "input", inputType: "image"})).to.be.false; expect(form.fieldTypeHasLabel({ type: "input", inputType: "button"})).to.be.false; expect(form.fieldTypeHasLabel({ type: "input", inputType: "submit"})).to.be.false; expect(form.fieldTypeHasLabel({ type: "input", inputType: "reset"})).to.be.false; }); it("should default to true for unknown types", () => { - expect(form.fieldTypeHasLabel({ type: "input", inputType: "unsupported-or-unknown"})).to.be.true; + expect(form.fieldTypeHasLabel({ type: "input", inputType: "unsupported-or-unknown", label:"unsupported"})).to.be.true; + expect(form.fieldTypeHasLabel({ type: "input", inputType: "unsupported-or-unknown"})).to.be.false; }); });