All files / src/fieldcontrols ShortText.ts

100% Statements 11/11
80% Branches 8/10
100% Functions 2/2
100% Lines 9/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47            1x   1x 1x   1x                       1x     1x   1x         1x               3x          
/**
 * @module FieldControls
 * 
 */ /** */
 
import { FieldSettings } from 'sn-client-js';
import { customElement } from 'aurelia-framework';
 
import { FieldBaseControl } from './FieldBaseControl';
import { ValidationRules } from 'aurelia-validation';
 
import { MDCTextField } from '@material/textfield/dist/mdc.textfield';
 
 
/**
 * Field control for general Short Text fields.
 * Usage:
 * 
 * ``` html
 * <short-text content.bind="content" settings.bind="myShortTextFieldSettings"></short-text>
 * ```
 */
@customElement('short-text')
export class ShortText extends FieldBaseControl<string, FieldSettings.ShortTextFieldSetting> {
 
    get rules(): any {
        const parentRules = super.rules;
 
        let thisRules = this.settings && ValidationRules
            .ensure('value')
                .minLength(this.settings.MinLength || 0)
                .maxLength(this.settings.MaxLength || Infinity)
                .matches(this.settings.Regex && new RegExp(this.settings.Regex) || new RegExp('')).rules || [];
        return [...parentRules, ...thisRules];
    }
 
 
    textfield: HTMLElement;
    mdcTextField: MDCTextField;
 
    attached(){
        this.mdcTextField = new MDCTextField(this.textfield);
    }
 
}