mirror of
https://github.com/bitwarden/web
synced 2025-12-06 00:03:28 +00:00
* Break form controls up into reusable components * Add proper form styling, validation, inline error messages, etc * Move control options into class instead of template * Add accessibility
49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import { Component, Input, OnInit } from "@angular/core";
|
|
|
|
import { BaseCvaComponent } from "./base-cva.component";
|
|
|
|
/** For use in the SSO Config Form only - will be deprecated by the Component Library */
|
|
@Component({
|
|
selector: "app-input-text[label][controlId]",
|
|
templateUrl: "input-text.component.html",
|
|
})
|
|
export class InputTextComponent extends BaseCvaComponent implements OnInit {
|
|
@Input() helperTextSameAsError: string;
|
|
@Input() requiredErrorMessage: string;
|
|
@Input() stripSpaces = false;
|
|
|
|
transformValue: (value: string) => string = null;
|
|
|
|
ngOnInit() {
|
|
super.ngOnInit();
|
|
if (this.stripSpaces) {
|
|
this.transformValue = this.doStripSpaces;
|
|
}
|
|
}
|
|
|
|
writeValue(value: string) {
|
|
this.internalControl.setValue(value == null ? "" : value);
|
|
}
|
|
|
|
protected onValueChangesInternal: any = (value: string) => {
|
|
let newValue = value;
|
|
if (this.transformValue != null) {
|
|
newValue = this.transformValue(value);
|
|
this.internalControl.setValue(newValue, { emitEvent: false });
|
|
}
|
|
this.onChange(newValue);
|
|
};
|
|
|
|
protected onValueChangeInternal(value: string) {
|
|
let newValue = value;
|
|
if (this.transformValue != null) {
|
|
newValue = this.transformValue(value);
|
|
this.internalControl.setValue(newValue, { emitEvent: false });
|
|
}
|
|
}
|
|
|
|
private doStripSpaces(value: string) {
|
|
return value.replace(/ /g, "");
|
|
}
|
|
}
|