]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/directives/trim.directive.ts
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / directives / trim.directive.ts
1 import { Directive, HostListener } from '@angular/core';
2 import { NgControl } from '@angular/forms';
3
4 import * as _ from 'lodash';
5
6 @Directive({
7 selector: '[cdTrim]'
8 })
9 export class TrimDirective {
10 constructor(private ngControl: NgControl) {}
11
12 @HostListener('input', ['$event.target.value'])
13 onInput(value) {
14 this.setValue(value);
15 }
16
17 setValue(value: string): void {
18 value = _.isString(value) ? value.trim() : value;
19 this.ngControl.control.setValue(value);
20 }
21 }