Skip to content

Commit 287c1b2

Browse files
committed
working on field validation
1 parent 39fdd46 commit 287c1b2

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

src/components/FormlyField.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
3939
let validator = this.field.validators[validKey];
4040
41-
let valid = typeof validator == 'function' ? !validator(field) : !eval(validator);
41+
let valid = typeof validator == 'function' ? !validator(field, model) : !eval(validator);
4242
setError(this.form, this.field.key, validKey, valid);
4343
4444
});

test/unit/specs/FormlyField.spec.js

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -161,64 +161,69 @@ describe('FormlyField', () => {
161161
done();
162162
},0);
163163
});
164-
165-
});
166-
167-
/*
168164

169165
it('should not require non-required values', (done) => {
170166
let data = {
171167
form: {
172168
$valid: true,
173-
$errors: {},
174-
search: {
169+
$errors: {}
170+
},
171+
model: {
172+
search: ''
173+
},
174+
fields: [
175+
{
176+
key: 'search',
175177
type: 'test',
176-
value: '',
177178
validators: {
178179
expression: 'field.value == "test"'
179180
}
180181
}
181-
}
182+
]
182183
};
183184

184185
createValidField(data);
185186
expect(vm.form.$errors.search.expression).to.be.false;
186187

187-
vm.$set('form.search.value', 'testing');
188+
vm.model.search = 'testing';
188189
setTimeout(()=>{
189190
expect(vm.form.$errors.search.expression).to.be.true;
190191
done();
191192
},0);
192-
});
193+
});
193194

194195
it('should take a function', (done) => {
195196
let data = {
196197
form: {
197198
$valid: true,
198-
$errors: {},
199-
search: {
199+
$errors: {}
200+
},
201+
model: {
202+
search: 'testing'
203+
},
204+
fields: [
205+
{
206+
key: 'search',
200207
type: 'test',
201-
value: 'testing',
202208
validators: {
203-
expression: function(field){
204-
return field.value == 'test';
209+
expression: function(field, model){
210+
return model.search == 'test';
205211
}
206212
}
207213
}
208-
}
214+
]
209215
};
210216

211217
createValidField(data);
212218
expect(vm.form.$errors.search.expression).to.be.true;
213-
214-
vm.$set('form.search.value', 'test');
219+
vm.model.search = 'test';
215220
setTimeout(()=>{
216221
expect(vm.form.$errors.search.expression).to.be.false;
217222
done();
218223
},0);
219224
});
220225

221226
});
222-
*/
227+
223228
});
224229

0 commit comments

Comments
 (0)