-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add html text formly field type
- Loading branch information
Showing
6 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/app/shared/formly/types/html-text-field/html-text-field.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<div [ngClass]="to.inputClass ? to.inputClass : 'col-form-label'" [innerHtml]="textValue"></div> |
65 changes: 65 additions & 0 deletions
65
src/app/shared/formly/types/html-text-field/html-text-field.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { FormGroup } from '@angular/forms'; | ||
import { FormlyFieldConfig, FormlyModule } from '@ngx-formly/core'; | ||
|
||
import { FormlyTestingComponentsModule } from 'ish-shared/formly/dev/testing/formly-testing-components.module'; | ||
import { FormlyTestingContainerComponent } from 'ish-shared/formly/dev/testing/formly-testing-container/formly-testing-container.component'; | ||
|
||
import { HtmlTextFieldComponent } from './html-text-field.component'; | ||
|
||
describe('Html Text Field Component', () => { | ||
let component: FormlyTestingContainerComponent; | ||
let fixture: ComponentFixture<FormlyTestingContainerComponent>; | ||
let element: HTMLElement; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [HtmlTextFieldComponent], | ||
imports: [ | ||
FormlyModule.forRoot({ | ||
types: [ | ||
{ | ||
name: 'ish-html-text-field', | ||
component: HtmlTextFieldComponent, | ||
}, | ||
], | ||
}), | ||
FormlyTestingComponentsModule, | ||
], | ||
}).compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
const testComponentInputs = { | ||
fields: [ | ||
{ | ||
key: 'displayValue', | ||
type: 'ish-html-text-field', | ||
templateOptions: { | ||
label: 'test label', | ||
}, | ||
} as FormlyFieldConfig, | ||
], | ||
form: new FormGroup({}), | ||
model: { | ||
displayValue: 'testValue', | ||
}, | ||
}; | ||
fixture = TestBed.createComponent(FormlyTestingContainerComponent); | ||
component = fixture.componentInstance; | ||
element = fixture.nativeElement; | ||
|
||
component.testComponentInputs = testComponentInputs; | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(component).toBeTruthy(); | ||
expect(element).toBeTruthy(); | ||
expect(() => fixture.detectChanges()).not.toThrow(); | ||
}); | ||
|
||
it('should be rendered after creation', () => { | ||
fixture.detectChanges(); | ||
expect(element.querySelector('ish-html-text-field > div.col-form-label')).toBeTruthy(); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
src/app/shared/formly/types/html-text-field/html-text-field.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { ChangeDetectionStrategy, Component } from '@angular/core'; | ||
import { FieldType } from '@ngx-formly/core'; | ||
|
||
/** | ||
* Type to display a html text value with optional styling | ||
* | ||
* @templateOption **inputClass** a class that will be used to style the div around the text | ||
*/ | ||
@Component({ | ||
selector: 'ish-html-text-field', | ||
templateUrl: './html-text-field.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class HtmlTextFieldComponent extends FieldType { | ||
get textValue() { | ||
return this.form.get(this.field.key as string)?.value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters