Skip to content

Commit 356241b

Browse files
committed
Fix this in schema functions
1 parent 369b69f commit 356241b

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

src/formGenerator.vue

+5-5
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ div
153153
// Get disabled attr of field
154154
fieldDisabled(field) {
155155
if (isFunction(field.disabled))
156-
return field.disabled(this.model);
156+
return field.disabled.call(this, this.model, field, this);
157157
158158
if (isNil(field.disabled))
159159
return false;
@@ -164,7 +164,7 @@ div
164164
// Get required prop of field
165165
fieldRequired(field) {
166166
if (isFunction(field.required))
167-
return field.required(this.model);
167+
return field.required.call(this, this.model, field, this);
168168
169169
if (isNil(field.required))
170170
return false;
@@ -175,7 +175,7 @@ div
175175
// Get visible prop of field
176176
fieldVisible(field) {
177177
if (isFunction(field.visible))
178-
return field.visible(this.model);
178+
return field.visible.call(this, this.model, field, this);
179179
180180
if (isNil(field.visible))
181181
return true;
@@ -186,7 +186,7 @@ div
186186
// Get readonly prop of field
187187
fieldReadonly(field) {
188188
if (isFunction(field.readonly))
189-
return field.readonly(this.model);
189+
return field.readonly.call(this, this.model, field, this);
190190
191191
if (isNil(field.readonly))
192192
return false;
@@ -197,7 +197,7 @@ div
197197
// Get featured prop of field
198198
fieldFeatured(field) {
199199
if (isFunction(field.featured))
200-
return field.featured(this.model);
200+
return field.featured.call(this, this.model, field, this);
201201
202202
if (isNil(field.featured))
203203
return false;

test/unit/specs/VueFormGenerator.spec.js

+31-1
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,36 @@ describe("VueFormGenerator.vue", () => {
281281

282282
});
283283

284+
describe("check fieldDisabled function parameters", () => {
285+
let schema = {
286+
fields: [
287+
{
288+
type: "input",
289+
inputType: "text",
290+
label: "Name",
291+
model: "name",
292+
disabled: sinon.spy()
293+
}
294+
]
295+
};
296+
297+
let model = {
298+
name: "John Doe",
299+
status: true
300+
};
301+
302+
before( () => {
303+
createFormGenerator(schema, model);
304+
});
305+
306+
it("should be called with correct params", () => {
307+
let spy = schema.fields[0].disabled;
308+
expect(spy.called).to.be.true;
309+
expect(spy.calledWith(model, schema.fields[0], vm.$children[0])).to.be.true;
310+
});
311+
312+
});
313+
284314
describe("check fieldDisabled with const", () => {
285315
let schema = {
286316
fields: [
@@ -629,7 +659,7 @@ describe("VueFormGenerator.vue", () => {
629659

630660
});
631661

632-
describe.only("check onValidated event", () => {
662+
describe("check onValidated event", () => {
633663
let schema = {
634664
fields: [
635665
{

0 commit comments

Comments
 (0)