From 8ecc851ab3acd3412dd83c56c33be2ed11209903 Mon Sep 17 00:00:00 2001 From: David Higgins Date: Wed, 15 Nov 2017 14:37:21 -0500 Subject: [PATCH 1/2] don't render labels when no label text is provided, proposed option 1 from #347 --- src/formGenerator.vue | 2 ++ 1 file changed, 2 insertions(+) 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; From f0c2281ece73fc0beb44b68c1636e9461c5ed575 Mon Sep 17 00:00:00 2001 From: David Higgins Date: Wed, 15 Nov 2017 14:45:43 -0500 Subject: [PATCH 2/2] updated tests for modified label logic --- test/unit/specs/VueFormGenerator.spec.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) 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; }); });