diff options
Diffstat (limited to 'src/pybind/mgr/dashboard/frontend/src/app/shared/directives/trim.directive.ts')
-rw-r--r-- | src/pybind/mgr/dashboard/frontend/src/app/shared/directives/trim.directive.ts | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/directives/trim.directive.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/directives/trim.directive.ts new file mode 100644 index 000000000..4b3604e43 --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/directives/trim.directive.ts @@ -0,0 +1,21 @@ +import { Directive, HostListener } from '@angular/core'; +import { NgControl } from '@angular/forms'; + +import _ from 'lodash'; + +@Directive({ + selector: '[cdTrim]' +}) +export class TrimDirective { + constructor(private ngControl: NgControl) {} + + @HostListener('input', ['$event.target.value']) + onInput(value: string) { + this.setValue(value); + } + + setValue(value: string): void { + value = _.isString(value) ? value.trim() : value; + this.ngControl.control.setValue(value); + } +} |