Skip to content

Commit

Permalink
fix(core): add default wrappers when type is set (#630)
Browse files Browse the repository at this point in the history
  • Loading branch information
aitboudad authored Jan 5, 2018
1 parent ff6a4dd commit 2dd41ab
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/core/src/services/formly.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class FormlyConfig {
} = {
fieldTransform: undefined,
showError: function(field: Field) {
return (field.formControl.touched || (field.options.parentForm && field.options.parentForm.submitted) || (field.field.validation && field.field.validation.show)) && field.formControl.invalid;
return field.formControl && field.formControl.invalid && (field.formControl.touched || (field.options.parentForm && field.options.parentForm.submitted) || (field.field.validation && field.field.validation.show));
},
};

Expand Down
7 changes: 7 additions & 0 deletions src/core/src/services/formly.form.builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,13 @@ describe('FormlyFormBuilder service', () => {
expect(field.key).toEqual('nested.title');
expect(field.wrappers).toEqual([]);
});

it('should add default wrappers if type is provided', () => {
field = { type: 'input' };
builder.buildForm(form, [field], {}, {});

expect(field.wrappers).toEqual(['label']);
});
});

describe('initialise field validators', () => {
Expand Down
14 changes: 8 additions & 6 deletions src/core/src/services/formly.form.builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,15 @@ export class FormlyFormBuilder {

private initFieldOptions(field: FormlyFieldConfig) {
field.templateOptions = field.templateOptions || {};
if (field.key && field.type) {
if (field.type) {
this.formlyConfig.getMergedField(field);
field.templateOptions = Object.assign({
label: '',
placeholder: '',
focus: false,
}, field.templateOptions);
if (field.key) {
field.templateOptions = Object.assign({
label: '',
placeholder: '',
focus: false,
}, field.templateOptions);
}
}
}

Expand Down

0 comments on commit 2dd41ab

Please sign in to comment.