Blame view

src/helpers/validate.component.ts 1.27 KB
7085f966   Yarik   Validation try
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  import { Component, ViewContainerRef, ViewChild, AfterViewInit } from '@angular/core';
  import { FormGroup } from '@angular/forms';
  
  import { AgEditorComponent } from 'ag-grid-ng2/main';
  
  @Component({
      selector: 'editor-cell',
      templateUrl: './validate.component.html',
  })
  export class ValidateComponent implements AgEditorComponent, AfterViewInit {
      private params: any;
      private value: string = null;
  
      @ViewChild('container', {read: ViewContainerRef}) public container: any;
      public form: FormGroup;
      public field: string;
  
      ngAfterViewInit(): void {
          this.container.element.nativeElement.focus();
      }
  
      agInit(params: any): void {
          this.params = params;
          this.form = params.form;
          this.field = params.field;
      }
  
      getValue(): any {
          console.log('From getter', this.value);
          return this.value;
      }
  
      setValue(value: string): void {
          this.value = value;
          console.log('From setter', this.value);
      }
  
      isPopup(): boolean {
          return true;
      }
  
      editorChange(event): boolean {
          event.preventDefault();
          event.stopPropagation();
          this.setValue(this.form.value[this.field]);
          this.params.api.stopEditing();
          event.stopPropagation();
          return false;
      }
  }