Skip to content

Commit

Permalink
feat(form): dynamic forms now support textareas
Browse files Browse the repository at this point in the history
  • Loading branch information
cbourget committed Jun 13, 2019
1 parent 8f377b5 commit bf8d081
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<mat-form-field>
<textarea
matInput
[required]="required"
[placeholder]="placeholder"
[formControl]="formControl">
</textarea>
<mat-error *ngIf="formControl.errors">{{getErrorMessage() | translate}}</mat-error>
</mat-form-field>
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import {
Input,
Component,
ChangeDetectionStrategy,
} from '@angular/core';
import { FormControl } from '@angular/forms';

import { formControlIsRequired, getControlErrorMessage } from '../shared/form.utils';
import { FormFieldComponent } from '../shared/form-field-component';

/**
* This component renders a textarea field
*/
@FormFieldComponent('textarea')
@Component({
selector: 'igo-form-field-textarea',
templateUrl: './form-field-textarea.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
})
export class FormFieldTextareaComponent {

/**
* The field's form control
*/
@Input() formControl: FormControl;

/**
* Field placeholder
*/
@Input() placeholder: string;

/**
* Field placeholder
*/
@Input() errors: {[key: string]: string};

/**
* Whether the field is required
*/
get required(): boolean {
return formControlIsRequired(this.formControl);
}

/**
* Get error message
*/
getErrorMessage(): string {
return getControlErrorMessage(this.formControl, this.errors);
}

}
7 changes: 5 additions & 2 deletions packages/common/src/lib/form/form-field/form-field.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { IgoDynamicOutletModule } from '../../dynamic-component/dynamic-outlet/d
import { FormFieldComponent } from './form-field.component';
import { FormFieldSelectComponent } from './form-field-select.component';
import { FormFieldTextComponent } from './form-field-text.component';
import { FormFieldTextareaComponent } from './form-field-textarea.component';

/**
* @ignore
Expand All @@ -33,12 +34,14 @@ import { FormFieldTextComponent } from './form-field-text.component';
exports: [
FormFieldComponent,
FormFieldSelectComponent,
FormFieldTextComponent
FormFieldTextComponent,
FormFieldTextareaComponent
],
declarations: [
FormFieldComponent,
FormFieldSelectComponent,
FormFieldTextComponent
FormFieldTextComponent,
FormFieldTextareaComponent
]
})
export class IgoFormFieldModule {}
4 changes: 3 additions & 1 deletion packages/common/src/lib/form/form.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { IgoFormGroupModule } from './form-group/form-group.module';
import { IgoFormFieldModule } from './form-field/form-field.module';
import { FormFieldSelectComponent } from './form-field/form-field-select.component';
import { FormFieldTextComponent } from './form-field/form-field-text.component';
import { FormFieldTextareaComponent } from './form-field/form-field-textarea.component';
import { FormService } from './shared/form.service';
import { FormFieldService } from './shared/form-field.service';

Expand All @@ -30,7 +31,8 @@ import { FormFieldService } from './shared/form-field.service';
],
entryComponents: [
FormFieldSelectComponent,
FormFieldTextComponent
FormFieldTextComponent,
FormFieldTextareaComponent
]
})
export class IgoFormModule {}

0 comments on commit bf8d081

Please sign in to comment.