From df1649bac151ccb7a00244a3633f5ba3adf178a8 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 25 Apr 2018 17:53:37 -0400 Subject: [PATCH] input verbatim directive --- .../directives/input-verbatim.directive.ts | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/angular/directives/input-verbatim.directive.ts diff --git a/src/angular/directives/input-verbatim.directive.ts b/src/angular/directives/input-verbatim.directive.ts new file mode 100644 index 0000000000..570defe0d4 --- /dev/null +++ b/src/angular/directives/input-verbatim.directive.ts @@ -0,0 +1,37 @@ +import { + Directive, + ElementRef, + Input, + Renderer2, +} from '@angular/core'; + +@Directive({ + selector: '[appInputVerbatim]', +}) +export class InputVerbatimDirective { + @Input() set appInputVerbatim(condition: boolean | string) { + this.disableComplete = condition === '' || condition === true; + } + + private disableComplete: boolean; + + constructor(private el: ElementRef, private renderer: Renderer2) { } + + ngOnInit() { + if (this.disableComplete && !this.el.nativeElement.hasAttribute('autocomplete')) { + this.renderer.setAttribute(this.el.nativeElement, 'autocomplete', 'nope'); + } + if (!this.el.nativeElement.hasAttribute('autocapitalize')) { + this.renderer.setAttribute(this.el.nativeElement, 'autocapitalize', 'none'); + } + if (!this.el.nativeElement.hasAttribute('autocorrect')) { + this.renderer.setAttribute(this.el.nativeElement, 'autocorrect', 'none'); + } + if (!this.el.nativeElement.hasAttribute('spellcheck')) { + this.renderer.setAttribute(this.el.nativeElement, 'spellcheck', 'false'); + } + if (!this.el.nativeElement.hasAttribute('inputmode')) { + this.renderer.setAttribute(this.el.nativeElement, 'inputmode', 'verbatim'); + } + } +}