File tree Expand file tree Collapse file tree 2 files changed +25
-20
lines changed Expand file tree Collapse file tree 2 files changed +25
-20
lines changed Original file line number Diff line number Diff line change 38
38
39
39
let validator = this .field .validators [validKey];
40
40
41
- let valid = typeof validator == ' function' ? ! validator (field) : ! eval (validator);
41
+ let valid = typeof validator == ' function' ? ! validator (field, model ) : ! eval (validator);
42
42
setError (this .form , this .field .key , validKey, valid);
43
43
44
44
});
Original file line number Diff line number Diff line change @@ -161,64 +161,69 @@ describe('FormlyField', () => {
161
161
done ( ) ;
162
162
} , 0 ) ;
163
163
} ) ;
164
-
165
- } ) ;
166
-
167
- /*
168
164
169
165
it ( 'should not require non-required values' , ( done ) => {
170
166
let data = {
171
167
form : {
172
168
$valid : true ,
173
- $errors: {},
174
- search: {
169
+ $errors : { }
170
+ } ,
171
+ model : {
172
+ search : ''
173
+ } ,
174
+ fields : [
175
+ {
176
+ key : 'search' ,
175
177
type : 'test' ,
176
- value: '',
177
178
validators : {
178
179
expression : 'field.value == "test"'
179
180
}
180
181
}
181
- }
182
+ ]
182
183
} ;
183
184
184
185
createValidField ( data ) ;
185
186
expect ( vm . form . $errors . search . expression ) . to . be . false ;
186
187
187
- vm.$set('form .search.value', 'testing') ;
188
+ vm . model . search = 'testing' ;
188
189
setTimeout ( ( ) => {
189
190
expect ( vm . form . $errors . search . expression ) . to . be . true ;
190
191
done ( ) ;
191
192
} , 0 ) ;
192
- });
193
+ } ) ;
193
194
194
195
it ( 'should take a function' , ( done ) => {
195
196
let data = {
196
197
form : {
197
198
$valid : true ,
198
- $errors: {},
199
- search: {
199
+ $errors : { }
200
+ } ,
201
+ model : {
202
+ search : 'testing'
203
+ } ,
204
+ fields : [
205
+ {
206
+ key : 'search' ,
200
207
type : 'test' ,
201
- value: 'testing',
202
208
validators : {
203
- expression: function(field){
204
- return field.value == 'test';
209
+ expression : function ( field , model ) {
210
+ return model . search == 'test' ;
205
211
}
206
212
}
207
213
}
208
- }
214
+ ]
209
215
} ;
210
216
211
217
createValidField ( data ) ;
212
218
expect ( vm . form . $errors . search . expression ) . to . be . true ;
213
-
214
- vm.$set('form.search.value', 'test');
219
+ vm . model . search = 'test' ;
215
220
setTimeout ( ( ) => {
216
221
expect ( vm . form . $errors . search . expression ) . to . be . false ;
217
222
done ( ) ;
218
223
} , 0 ) ;
219
224
} ) ;
220
225
221
226
} ) ;
222
- */
227
+
223
228
} ) ;
224
229
You can’t perform that action at this time.
0 commit comments