All files / src/fieldcontrols short-text.ts

50% Statements 3/6
0% Branches 0/13
0% Functions 0/1
50% Lines 3/6
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          1x 1x   1x                                
import { FieldSettings, Content, Resources } from 'sn-client-js';
import { bindable, computedFrom } from 'aurelia-framework';
import { IFieldControl } from './IFieldControl';
 
import { AureliaClientFieldConfig } from '../AureliaClientFieldConfig';
import { FieldBaseControl } from './FieldBaseControl';
import { ValidationRules, FluentRules } from 'aurelia-validation';
 
export class ShortText extends FieldBaseControl<string, FieldSettings.ShortTextFieldSetting> {
 
    get rules(): any {
        const parentRules = super.rules || [];
 
        let thisRules = ValidationRules
            .ensure('value')
                .minLength(this.settings.MinLength || 0)
                .maxLength(this.settings.MaxLength || Infinity)
                .matches(this.settings.Regex && new RegExp(this.settings.Regex) || new RegExp(''))
 
        return [...(parentRules ? parentRules : []), ...(thisRules.rules ? thisRules.rules : [])];
    }
 
}