File tree 2 files changed +94
-2
lines changed
2 files changed +94
-2
lines changed Original file line number Diff line number Diff line change 106
106
let baseClasses = {
107
107
error: field .errors && field .errors .length > 0 ,
108
108
disabled: this .fieldDisabled (field),
109
- readonly: field . readonly ,
110
- featured: field . featured ,
109
+ readonly: this . fieldReadonly (field) ,
110
+ featured: this . fieldFeatured (field) ,
111
111
required: this .fieldRequired (field)
112
112
};
113
113
161
161
return field .visible ;
162
162
},
163
163
164
+ // Get readonly prop of field
165
+ fieldReadonly (field ) {
166
+ if (isFunction (field .readonly ))
167
+ return field .readonly (this .model );
168
+
169
+ if (isNil (field .readonly ))
170
+ return false ;
171
+
172
+ return field .readonly ;
173
+ },
174
+
175
+ // Get featured prop of field
176
+ fieldFeatured (field ) {
177
+ if (isFunction (field .featured ))
178
+ return field .featured (this .model );
179
+
180
+ if (isNil (field .featured ))
181
+ return false ;
182
+
183
+ return field .featured ;
184
+ },
185
+
164
186
// Validating the model properties
165
187
validate () {
166
188
this .clearValidationErrors ();
Original file line number Diff line number Diff line change @@ -306,6 +306,76 @@ describe("VueFormGenerator.vue", () => {
306
306
307
307
} ) ;
308
308
309
+ describe ( "check fieldReadonly with function" , ( ) => {
310
+ let schema = {
311
+ fields : [
312
+ {
313
+ type : "text" ,
314
+ label : "Name" ,
315
+ model : "name" ,
316
+ readonly ( model ) { return model . status ; }
317
+ }
318
+ ]
319
+ } ;
320
+
321
+ let model = {
322
+ name : "John Doe" ,
323
+ status : true
324
+ } ;
325
+
326
+ before ( ( ) => {
327
+ createFormGenerator ( schema , model ) ;
328
+ } ) ;
329
+
330
+ it ( "should be readonly" , ( ) => {
331
+ expect ( el . querySelector ( ".form-group" ) . classList . contains ( "readonly" ) ) . to . be . true ;
332
+ } ) ;
333
+
334
+ it ( "should be writable" , ( done ) => {
335
+ model . status = false ;
336
+ vm . $nextTick ( ( ) => {
337
+ expect ( el . querySelector ( ".form-group" ) . classList . contains ( "readonly" ) ) . to . be . false ;
338
+ done ( ) ;
339
+ } ) ;
340
+ } ) ;
341
+
342
+ } ) ;
343
+
344
+ describe ( "check fieldFeatured with function" , ( ) => {
345
+ let schema = {
346
+ fields : [
347
+ {
348
+ type : "text" ,
349
+ label : "Name" ,
350
+ model : "name" ,
351
+ featured ( model ) { return model . status ; }
352
+ }
353
+ ]
354
+ } ;
355
+
356
+ let model = {
357
+ name : "John Doe" ,
358
+ status : true
359
+ } ;
360
+
361
+ before ( ( ) => {
362
+ createFormGenerator ( schema , model ) ;
363
+ } ) ;
364
+
365
+ it ( "should be featured" , ( ) => {
366
+ expect ( el . querySelector ( ".form-group" ) . classList . contains ( "featured" ) ) . to . be . true ;
367
+ } ) ;
368
+
369
+ it ( "should not be featured" , ( done ) => {
370
+ model . status = false ;
371
+ vm . $nextTick ( ( ) => {
372
+ expect ( el . querySelector ( ".form-group" ) . classList . contains ( "featured" ) ) . to . be . false ;
373
+ done ( ) ;
374
+ } ) ;
375
+ } ) ;
376
+
377
+ } ) ;
378
+
309
379
describe ( "check fieldRequired with function" , ( ) => {
310
380
let schema = {
311
381
fields : [
You can’t perform that action at this time.
0 commit comments