]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
a3139f0e26494d3623749b830922b586d0cc3ff8
[ceph.git] /
1 import { Component, ViewChild, ElementRef } from '@angular/core';
2 import { FieldType, FieldTypeConfig } from '@ngx-formly/core';
3
4 @Component({
5   selector: 'cd-formly-textarea-type',
6   templateUrl: './formly-textarea-type.component.html',
7   styleUrls: ['./formly-textarea-type.component.scss']
8 })
9 export class FormlyTextareaTypeComponent extends FieldType<FieldTypeConfig> {
10   @ViewChild('textArea')
11   public textArea: ElementRef<any>;
12
13   onChange() {
14     const value = this.textArea.nativeElement.value;
15     try {
16       const formatted = JSON.stringify(JSON.parse(value), null, 2);
17       this.textArea.nativeElement.value = formatted;
18       this.textArea.nativeElement.style.height = 'auto';
19       const lineNumber = formatted.split('\n').length;
20       const pixelPerLine = 25;
21       const pixels = lineNumber * pixelPerLine;
22       this.textArea.nativeElement.style.height = pixels + 'px';
23     } catch (e) {}
24   }
25 }