Skip to content

Commit

Permalink
🐛 Fix options prop default #91
Browse files Browse the repository at this point in the history
  • Loading branch information
icebob committed Nov 3, 2016
1 parent a40e23c commit 3d2e821
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 9 deletions.
34 changes: 26 additions & 8 deletions src/formGenerator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,31 @@ div
export default {
components: fieldComponents,
props: [
"schema",
"options",
"model",
"multiple",
"isNewModel"
],
props: {
schema: Object,
model: Object,
options: {
type: Object,
default() {
return {
validateAfterLoad: false,
validateAfterChanged: false
}
}
},
multiple: {
type: Boolean,
default: false
},
isNewModel: {
type: Boolean,
default: false
}
},
data () {
return {
Expand Down Expand Up @@ -76,7 +94,7 @@ div
compiled() {
// First load, running validation if neccessary
if (this.options && this.options.validateAfterLoad === true && this.isNewModel !== true)
if (this.options.validateAfterLoad === true && this.isNewModel !== true)
this.validate();
else
this.clearValidationErrors();
Expand Down
35 changes: 34 additions & 1 deletion test/unit/specs/VueFormGenerator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Vue.use(VueFormGenerator);

let el, vm;

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

});

describe("check if option null", () => {
let schema = {
fields: [
{
type: "text",
label: "Name",
model: "name"
}
]
};

let model = { name: "Me" };
let form, el, vm;

before( () => {
[el, vm] = createFormGenerator(schema, model);
form = vm.$refs.form;
document.body.appendChild(el);
});

after( () => {
document.body.removeChild(el);
});

it("should be validation error at ready()", (done) => {
vm.$nextTick( () => {
expect(form).to.be.defined;
expect(form.options).to.be.defined;
done();
});
});
});

describe("check validateAfterLoad option", () => {
let schema = {
fields: [
Expand Down

0 comments on commit 3d2e821

Please sign in to comment.