Skip to content

Commit

Permalink
Merge pull request #198 from lionel-bijaoui/lb_custom_main_tag
Browse files Browse the repository at this point in the history
Add a props to change the main tag
  • Loading branch information
lionel-bijaoui authored May 16, 2017
2 parents 452d492 + c728597 commit a6aaf1b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
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

0 comments on commit a6aaf1b

Please sign in to comment.