summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/dashboard/frontend/src/app/shared/forms/crud-form/formly-textarea-type/formly-textarea-type.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/pybind/mgr/dashboard/frontend/src/app/shared/forms/crud-form/formly-textarea-type/formly-textarea-type.component.ts')
-rw-r--r--src/pybind/mgr/dashboard/frontend/src/app/shared/forms/crud-form/formly-textarea-type/formly-textarea-type.component.ts25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/forms/crud-form/formly-textarea-type/formly-textarea-type.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/forms/crud-form/formly-textarea-type/formly-textarea-type.component.ts
new file mode 100644
index 000000000..a3139f0e2
--- /dev/null
+++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/forms/crud-form/formly-textarea-type/formly-textarea-type.component.ts
@@ -0,0 +1,25 @@
+import { Component, ViewChild, ElementRef } from '@angular/core';
+import { FieldType, FieldTypeConfig } from '@ngx-formly/core';
+
+@Component({
+ selector: 'cd-formly-textarea-type',
+ templateUrl: './formly-textarea-type.component.html',
+ styleUrls: ['./formly-textarea-type.component.scss']
+})
+export class FormlyTextareaTypeComponent extends FieldType<FieldTypeConfig> {
+ @ViewChild('textArea')
+ public textArea: ElementRef<any>;
+
+ onChange() {
+ const value = this.textArea.nativeElement.value;
+ try {
+ const formatted = JSON.stringify(JSON.parse(value), null, 2);
+ this.textArea.nativeElement.value = formatted;
+ this.textArea.nativeElement.style.height = 'auto';
+ const lineNumber = formatted.split('\n').length;
+ const pixelPerLine = 25;
+ const pixels = lineNumber * pixelPerLine;
+ this.textArea.nativeElement.style.height = pixels + 'px';
+ } catch (e) {}
+ }
+}