Skip to content

Add a props to change the main tag #198

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

Merged
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
10 changes: 9 additions & 1 deletion src/formGenerator.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template lang="pug">
div
fieldset.vue-form-generator(v-if='schema != null')
fieldset.vue-form-generator(v-if='schema != null', :is='tag')
template(v-for='field in fields')
.form-group(v-if='fieldVisible(field)', :class='getFieldRowClasses(field)')
label
Expand Down Expand Up @@ -70,6 +70,14 @@ div
isNewModel: {
type: Boolean,
default: false
},

tag: {
type: String,
default: "fieldset",
validator: function (value) {
return value.length > 0;
}
}
},

Expand Down
25 changes: 25 additions & 0 deletions test/unit/specs/VueFormGenerator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,31 @@ describe("VueFormGenerator.vue", () => {
expect(el.getElementsByTagName("fieldset")).to.be.length(1);
});

});

describe("with empty schema and custom tag", () => {
let schema = {};

beforeEach( () => {
let elm = document.createElement("div");
vm = new Vue({
// eslint-disable-next-line quotes
template: `<vue-form-generator :schema="schema" ref="form" tag="div"></vue-form-generator>`,
data: {
schema
}
}).$mount(elm);

el = vm.$el;

return [el, vm];
});

it("should be create fieldset", () => {
expect(vm.$el).to.be.exist;
expect(el.getElementsByTagName("div")).to.be.length(1);
});

});

describe("check form-group classes", () => {
Expand Down