Skip to content
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: 2 additions & 0 deletions src/formGenerator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 16 additions & 5 deletions test/unit/specs/VueFormGenerator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
});

Expand Down