Skip to content
Snippets Groups Projects
text-field.ts 3.05 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { Type } from '@angular/core';
    
    import {
      BasicStyles, InputAssistancePreset, InputElement,
    
    rhenck's avatar
    rhenck committed
      PositionedUIElement, PositionProperties, AnswerScheme, UIElement
    
    } 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';
    
    rhenck's avatar
    rhenck committed
      minLength: number | null = null;
    
      minLengthWarnMessage: string = 'Eingabe zu kurz';
    
    rhenck's avatar
    rhenck committed
      maxLength: number | null = null;
    
      maxLengthWarnMessage: string = 'Eingabe zu lang';
    
    rhenck's avatar
    rhenck committed
      pattern: string | null = null;
    
      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;
      };
    
    
    rhenck's avatar
    rhenck committed
      constructor(element: Partial<TextFieldElement>) {
        super({ width: 180, height: 120, ...element });
    
    rhenck's avatar
    rhenck committed
        if (element.appearance) this.appearance = element.appearance;
    
    rhenck's avatar
    rhenck committed
        if (element.minLength !== undefined) this.minLength = element.minLength;
    
    rhenck's avatar
    rhenck committed
        if (element.minLengthWarnMessage) this.minLengthWarnMessage = element.minLengthWarnMessage;
    
    rhenck's avatar
    rhenck committed
        if (element.maxLength !== undefined) this.maxLength = element.maxLength;
    
    rhenck's avatar
    rhenck committed
        if (element.maxLengthWarnMessage) this.maxLengthWarnMessage = element.maxLengthWarnMessage;
    
    rhenck's avatar
    rhenck committed
        if (element.pattern !== undefined) this.pattern = element.pattern;
    
    rhenck's avatar
    rhenck committed
        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;
        }
    
    rhenck's avatar
    rhenck committed
        if (element.showSoftwareKeyboard) this.showSoftwareKeyboard = element.showSoftwareKeyboard;
        if (element.softwareKeyboardShowFrench) this.softwareKeyboardShowFrench = element.softwareKeyboardShowFrench;
        if (element.clearable) this.clearable = element.clearable;
    
    rhenck's avatar
    rhenck committed
        this.position = UIElement.initPositionProps(element.position);
    
        this.styling = {
    
    rhenck's avatar
    rhenck committed
          ...UIElement.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: [],
    
      getElementComponent(): Type<ElementComponent> {
    
        return TextFieldComponent;
      }
    }