Skip to content

Commit 1ffe899

Browse files
authored
fix(#514): avoid supress and/or force validation messages. (#524)
1 parent bad3ecb commit 1ffe899

File tree

6 files changed

+9
-16
lines changed

6 files changed

+9
-16
lines changed

demo/src/formly/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const NgFormlyConfig: ConfigOption = {
4040
],
4141
extras: {
4242
showError: (field: Field) => {
43-
return (field.formState.submitted || field.formControl.touched) && !field.formControl.valid;
43+
return (field.formState.submitted || field.formControl.touched || (field.field.validation && field.field.validation.show)) && !field.formControl.valid;
4444
},
4545
},
4646
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ngx-formly/platform",
3-
"version": "2.0.0-alpha.2",
3+
"version": "2.0.0-alpha.3",
44
"author": "Zama Khan Mohammed <mohammedzamakhan@gmail.com>",
55
"contributors": [
66
"Zama Khan Mohammed <mohammedzamakhan@gmail.com>",

src/core/src/components/formly.field.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,6 @@ export class FormlyField implements DoCheck, OnInit, OnDestroy {
213213
if (formControl.status !== 'DISABLED' && this.field.templateOptions.disabled) {
214214
formControl.disable();
215215
}
216-
if (!formControl.dirty && formControl.invalid && this.field.validation && !this.field.validation.show) {
217-
formControl.markAsUntouched();
218-
}
219-
if (!formControl.dirty && formControl.invalid && this.field.validation && this.field.validation.show) {
220-
formControl.markAsTouched();
221-
}
222216
}
223217
}
224218
}

src/core/src/services/formly.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class FormlyConfig {
3434
} = {
3535
fieldTransform: undefined,
3636
showError: function(field: Field) {
37-
return field.formControl.touched && !field.formControl.valid;
37+
return (field.formControl.touched || (field.field.validation && field.field.validation.show)) && !field.formControl.valid;
3838
},
3939
};
4040

src/core/src/services/formly.form.builder.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,17 +199,19 @@ describe('FormlyFormBuilder service', () => {
199199
it('should show error when option `show` is true', () => {
200200
field.validators = { validation: ['required'] };
201201
field.validation = { show: true };
202-
builder.buildForm(form, [field], {}, {});
202+
const options: any = {};
203+
builder.buildForm(form, [field], {}, options);
203204

204-
expect(form.get('title').touched).toBeTruthy();
205+
expect(options.showError({ field: field, formControl: form })).toBeTruthy();
205206
});
206207

207208
it('should not show error when option `show` is false', () => {
208209
field.validators = { validation: ['required'] };
209210
field.validation = { show: false };
210-
builder.buildForm(form, [field], {}, {});
211+
const options: any = {};
212+
builder.buildForm(form, [field], {}, options);
211213

212-
expect(form.get('title').touched).toBeFalsy();
214+
expect(options.showError({ field: field, formControl: form })).toBeFalsy();
213215
});
214216
});
215217

src/core/src/services/formly.form.builder.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,6 @@ export class FormlyFormBuilder {
261261
}
262262

263263
this.addControl(form, name, formControl, field);
264-
if (field.validation && field.validation.show) {
265-
form.get(field.key).markAsTouched();
266-
}
267264
}
268265

269266
private getValidation(opt, value) {

0 commit comments

Comments
 (0)