Skip to content

Commit 41d583e

Browse files
author
Walker Leite
committed
change required check to exactly equal false
1 parent 925864f commit 41d583e

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/components/FormlyField.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export default {
6060

6161
Object.keys(this.field.validators).forEach((validKey) => {
6262
if ( !this.form.$errors[this.field.key][validKey] ) this.$set(this.form.$errors[ this.field.key ], validKey, false);
63-
if ( !this.field.required && !this.model[ this.field.key ] ) {
63+
if ( this.field.required === false && !this.model[ this.field.key ] ) {
6464
setError(this.form, this.field.key, validKey, false );
6565
return resolve();
6666
}

test/unit/specs/FormlyField.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ describe('FormlyField', () => {
396396
{
397397
key: 'search',
398398
type: 'test',
399+
required: false,
399400
validators: {
400401
expression: 'field.value == "test"'
401402
}
@@ -446,6 +447,29 @@ describe('FormlyField', () => {
446447
},0);
447448
});
448449

450+
it('should run validators even if require does not exists and model is empty', done => {
451+
let data = {
452+
form: {
453+
$valid: true,
454+
$errors: {}
455+
},
456+
model: {
457+
search: null
458+
},
459+
fields: [
460+
{
461+
key: 'search',
462+
type: 'test',
463+
validators: {
464+
aValidator: () => done()
465+
}
466+
}
467+
]
468+
};
469+
470+
createValidField(data);
471+
})
472+
449473
it('Async Validation', (done) => {
450474
let data = {
451475
form: {

0 commit comments

Comments
 (0)