Skip to content

Commit 3d2e821

Browse files
committed
🐛 Fix options prop default #91
1 parent a40e23c commit 3d2e821

File tree

2 files changed

+60
-9
lines changed

2 files changed

+60
-9
lines changed

src/formGenerator.vue

+26-8
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,31 @@ div
3232
export default {
3333
components: fieldComponents,
3434
35-
props: [
36-
"schema",
37-
"options",
38-
"model",
39-
"multiple",
40-
"isNewModel"
41-
],
35+
props: {
36+
schema: Object,
37+
38+
model: Object,
39+
40+
options: {
41+
type: Object,
42+
default() {
43+
return {
44+
validateAfterLoad: false,
45+
validateAfterChanged: false
46+
}
47+
}
48+
},
49+
50+
multiple: {
51+
type: Boolean,
52+
default: false
53+
},
54+
55+
isNewModel: {
56+
type: Boolean,
57+
default: false
58+
}
59+
},
4260
4361
data () {
4462
return {
@@ -76,7 +94,7 @@ div
7694
7795
compiled() {
7896
// First load, running validation if neccessary
79-
if (this.options && this.options.validateAfterLoad === true && this.isNewModel !== true)
97+
if (this.options.validateAfterLoad === true && this.isNewModel !== true)
8098
this.validate();
8199
else
82100
this.clearValidationErrors();

test/unit/specs/VueFormGenerator.spec.js

+34-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Vue.use(VueFormGenerator);
77

88
let el, vm;
99

10-
function createFormGenerator(schema = {}, model = null, options = {}, multiple = false) {
10+
function createFormGenerator(schema = {}, model = null, options, multiple) {
1111
el = document.createElement("div");
1212
// eslint-disable-next-line quotes
1313
el.innerHTML = `<vue-form-generator :schema="schema" :model="model" :options="options" :multiple="multiple" v-ref:form></vue-form-generator>`;
@@ -414,6 +414,39 @@ describe("VueFormGenerator.vue", () => {
414414

415415
});
416416

417+
describe("check if option null", () => {
418+
let schema = {
419+
fields: [
420+
{
421+
type: "text",
422+
label: "Name",
423+
model: "name"
424+
}
425+
]
426+
};
427+
428+
let model = { name: "Me" };
429+
let form, el, vm;
430+
431+
before( () => {
432+
[el, vm] = createFormGenerator(schema, model);
433+
form = vm.$refs.form;
434+
document.body.appendChild(el);
435+
});
436+
437+
after( () => {
438+
document.body.removeChild(el);
439+
});
440+
441+
it("should be validation error at ready()", (done) => {
442+
vm.$nextTick( () => {
443+
expect(form).to.be.defined;
444+
expect(form.options).to.be.defined;
445+
done();
446+
});
447+
});
448+
});
449+
417450
describe("check validateAfterLoad option", () => {
418451
let schema = {
419452
fields: [

0 commit comments

Comments
 (0)