Skip to content

Commit

Permalink
Fix this in schema functions
Browse files Browse the repository at this point in the history
  • Loading branch information
icebob committed Feb 21, 2017
1 parent 369b69f commit 356241b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/formGenerator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ div
// Get disabled attr of field
fieldDisabled(field) {
if (isFunction(field.disabled))
return field.disabled(this.model);
return field.disabled.call(this, this.model, field, this);
if (isNil(field.disabled))
return false;
Expand All @@ -164,7 +164,7 @@ div
// Get required prop of field
fieldRequired(field) {
if (isFunction(field.required))
return field.required(this.model);
return field.required.call(this, this.model, field, this);
if (isNil(field.required))
return false;
Expand All @@ -175,7 +175,7 @@ div
// Get visible prop of field
fieldVisible(field) {
if (isFunction(field.visible))
return field.visible(this.model);
return field.visible.call(this, this.model, field, this);
if (isNil(field.visible))
return true;
Expand All @@ -186,7 +186,7 @@ div
// Get readonly prop of field
fieldReadonly(field) {
if (isFunction(field.readonly))
return field.readonly(this.model);
return field.readonly.call(this, this.model, field, this);
if (isNil(field.readonly))
return false;
Expand All @@ -197,7 +197,7 @@ div
// Get featured prop of field
fieldFeatured(field) {
if (isFunction(field.featured))
return field.featured(this.model);
return field.featured.call(this, this.model, field, this);
if (isNil(field.featured))
return false;
Expand Down
32 changes: 31 additions & 1 deletion test/unit/specs/VueFormGenerator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,36 @@ describe("VueFormGenerator.vue", () => {

});

describe("check fieldDisabled function parameters", () => {
let schema = {
fields: [
{
type: "input",
inputType: "text",
label: "Name",
model: "name",
disabled: sinon.spy()
}
]
};

let model = {
name: "John Doe",
status: true
};

before( () => {
createFormGenerator(schema, model);
});

it("should be called with correct params", () => {
let spy = schema.fields[0].disabled;
expect(spy.called).to.be.true;
expect(spy.calledWith(model, schema.fields[0], vm.$children[0])).to.be.true;
});

});

describe("check fieldDisabled with const", () => {
let schema = {
fields: [
Expand Down Expand Up @@ -629,7 +659,7 @@ describe("VueFormGenerator.vue", () => {

});

describe.only("check onValidated event", () => {
describe("check onValidated event", () => {
let schema = {
fields: [
{
Expand Down

0 comments on commit 356241b

Please sign in to comment.