Newer
Older
import { ElementFactory } from 'common/util/element.factory';
import {
BasicStyles, InputAssistancePreset, InputElement,
PositionedUIElement, PositionProperties, AnswerScheme
} from 'common/models/elements/element';
import { ElementComponent } from 'common/directives/element-component.directive';
import { TextFieldComponent } from 'common/components/input-elements/text-field.component';
export class TextFieldElement extends InputElement implements PositionedUIElement {
appearance: 'fill' | 'outline' = 'outline';
minLengthWarnMessage: string = 'Eingabe zu kurz';
maxLengthWarnMessage: string = 'Eingabe zu lang';
patternWarnMessage: string = 'Eingabe entspricht nicht der Vorgabe';
inputAssistancePreset: InputAssistancePreset = null;
inputAssistancePosition: 'floating' | 'right' = 'floating';
restrictedToInputAssistanceChars: boolean = true;
showSoftwareKeyboard: boolean = false;
softwareKeyboardShowFrench: boolean = false;
clearable: boolean = false;
position: PositionProperties;
styling: BasicStyles & {
lineHeight: number;
};
constructor(element: Partial<TextFieldElement>) {
super({ width: 180, height: 120, ...element });
if (element.appearance) this.appearance = element.appearance;
if (element.minLength !== undefined) this.minLength = element.minLength;
if (element.minLengthWarnMessage) this.minLengthWarnMessage = element.minLengthWarnMessage;
if (element.maxLength !== undefined) this.maxLength = element.maxLength;
if (element.maxLengthWarnMessage) this.maxLengthWarnMessage = element.maxLengthWarnMessage;
if (element.pattern !== undefined) this.pattern = element.pattern;
if (element.patternWarnMessage) this.patternWarnMessage = element.patternWarnMessage;
if (element.inputAssistancePreset) this.inputAssistancePreset = element.inputAssistancePreset;
if (element.inputAssistancePosition) this.inputAssistancePosition = element.inputAssistancePosition;
if (element.restrictedToInputAssistanceChars !== undefined) {
this.restrictedToInputAssistanceChars = element.restrictedToInputAssistanceChars;
}
if (element.showSoftwareKeyboard) this.showSoftwareKeyboard = element.showSoftwareKeyboard;
if (element.softwareKeyboardShowFrench) this.softwareKeyboardShowFrench = element.softwareKeyboardShowFrench;
if (element.clearable) this.clearable = element.clearable;
this.position = ElementFactory.initPositionProps(element.position);
this.styling = {
...ElementFactory.initStylingProps({
backgroundColor: 'transparent',
lineHeight: 135,
...element.styling
})
};
}
hasAnswerScheme(): boolean {
return Boolean(this.getAnswerScheme);
getAnswerScheme(): AnswerScheme {
return {
id: this.id,
type: 'string',
format: '',
multiple: false,
nullable: !this.value && this.value !== '',
values: [],
valuesComplete: false
};
}
getElementComponent(): Type<ElementComponent> {