Skip to content

Commit

Permalink
feat(dynamic-forms): adds hints to elements that allow mat-hints (Ter…
Browse files Browse the repository at this point in the history
  • Loading branch information
JulieMarie authored and emoralesb05 committed Aug 15, 2018
1 parent dc87ae0 commit 9f91753
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class DynamicFormsDemoComponent {

textElements: ITdDynamicElementConfig[] = [{
name: 'input',
hint: 'this is an input hint',
type: TdDynamicElement.Input,
required: false,
flex: 50,
Expand All @@ -65,6 +66,7 @@ export class DynamicFormsDemoComponent {
flex: 50,
}, {
name: 'textarea',
hint: 'this is a textarea hint',
type: TdDynamicElement.Textarea,
required: false,
}, {
Expand Down Expand Up @@ -114,6 +116,7 @@ export class DynamicFormsDemoComponent {
required: true,
}, {
name: 'value-label-select',
hint: 'this is a select hint',
type: TdDynamicElement.Select,
selections: [
{label: 'Test1', value: 1},
Expand All @@ -126,12 +129,14 @@ export class DynamicFormsDemoComponent {
fileElements: ITdDynamicElementConfig[] = [{
name: 'file-input',
label: 'Browse a file',
hint: 'this is a file input hint',
type: TdDynamicElement.FileInput,
}];

dateElements: ITdDynamicElementConfig[] = [{
name: 'date-input',
label: 'Select a date',
hint: 'this is a datepicker hint',
type: TdDynamicElement.Datepicker,
min: new Date(2018, 1, 1).setHours(0, 0, 0, 0),
}];
Expand Down
9 changes: 6 additions & 3 deletions src/platform/dynamic-forms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ Pass an array of javascript objects that implement [ITdDynamicElementConfig] wit
export interface ITdDynamicElementConfig {
label?: string;
name: string;
hint?: string;
type: TdDynamicType | TdDynamicElement | Type<any>;
required?: boolean;
min?: any;
max?: any;
minLength?: string;
maxLength?: string;
selections?: any[];
minLength?: any;
maxLength?: any;
selections?: any[] | { value: any, label: string }[];
default?: any;
flex?: number;
validators?: ITdDynamicElementValidator[];
}
```
Expand Down Expand Up @@ -99,6 +101,7 @@ export class DynamicCustomComponent {
export class Demo {
elements: ITdDynamicElementConfig[] = [{
name: 'input',
hint: 'hint',
type: TdDynamicElement.Input,
required: true,
}, {
Expand Down
6 changes: 6 additions & 0 deletions src/platform/dynamic-forms/dynamic-element.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ export class TdDynamicElementComponent extends _TdDynamicElementMixinBase
*/
@Input() label: string = '';

/**
* Sets hint to be displayed.
*/
@Input() hint: string = '';

/**
* Sets type or element of element to be rendered.
* Throws error if does not exist or no supported.
Expand Down Expand Up @@ -118,6 +123,7 @@ export class TdDynamicElementComponent extends _TdDynamicElementMixinBase
this._instance = ref.instance;
this._instance.control = this.dynamicControl;
this._instance.label = this.label;
this._instance.hint = this.hint;
this._instance.type = this.type;
this._instance.value = this.value;
this._instance.required = this.required;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[required]="required"
[min]="min"
[max]="max"/>
<mat-hint>{{hint}}</mat-hint>
<mat-datepicker-toggle matSuffix [for]="dynamicDatePicker"></mat-datepicker-toggle>
<mat-datepicker #dynamicDatePicker></mat-datepicker>
</mat-form-field>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export class TdDynamicDatepickerComponent {

label: string = '';

hint: string = '';

type: string = undefined;

required: boolean = undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
[value]="control?.value?.name"
[placeholder]="label"
readonly/>
<mat-hint>{{hint}}</mat-hint>
</mat-form-field>
<button mat-icon-button *ngIf="control.value" (click)="fileInput.clear()" (keyup.enter)="fileInput.clear()">
<mat-icon>cancel</mat-icon>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export class TdDynamicFileInputComponent {

label: string = '';

hint: string = '';

_handlefileDrop(value: File): void {
this.control.setValue(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
[attr.max]="max"
[attr.minLength]="minLength"
[attr.maxLength]="maxLength"/>
<mat-hint>{{hint}}</mat-hint>
</mat-form-field>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export class TdDynamicInputComponent {

label: string = '';

hint: string = '';

type: string = undefined;

required: boolean = undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
[required]="required">
<mat-option *ngFor="let selection of selections" [value]="selection.value || selection">{{selection.label || selection}}</mat-option>
</mat-select>
<mat-hint>{{hint}}</mat-hint>
</mat-form-field>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export class TdDynamicSelectComponent {

label: string = '';

hint: string = '';

required: boolean = undefined;

selections: any[] = undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
[required]="required"
rows="4">
</textarea>
<mat-hint>{{hint}}</mat-hint>
</mat-form-field>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export class TdDynamicTextareaComponent {

label: string = '';

hint: string = '';

required: boolean = undefined;

}
1 change: 1 addition & 0 deletions src/platform/dynamic-forms/dynamic-forms.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
[dynamicControl]="dynamicForm.controls[element.name]"
[id]="element.name"
[label]="element.label || element.name"
[hint]="element.hint"
[type]="element.type"
[required]="element.required"
[min]="element.min"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface ITdDynamicElementValidator {
export interface ITdDynamicElementConfig {
label?: string;
name: string;
hint?: string;
type: TdDynamicType | TdDynamicElement | Type<any>;
required?: boolean;
min?: any;
Expand Down

0 comments on commit 9f91753

Please sign in to comment.