1- import { Inject , InjectionToken } from '@angular/core' ;
1+ import { Inject , InjectionToken } from '@angular/core' ;
22
3- import uniqueId from 'lodash/uniqueId ' ;
4- import { DynamicFormControlLayout , DynamicFormControlRelation , MATCH_VISIBLE , OR_OPERATOR } from '@ng-dynamic-forms/core' ;
3+ import { uniqueId } from 'lodash' ;
4+ import { DynamicFormControlLayout , DynamicFormControlRelation , MATCH_VISIBLE , OR_OPERATOR } from '@ng-dynamic-forms/core' ;
55
66import { hasValue , isNotEmpty , isNotNull , isNotUndefined } from '../../../empty.util' ;
77import { FormFieldModel } from '../models/form-field.model' ;
@@ -22,6 +22,7 @@ export const SUBMISSION_ID: InjectionToken<string> = new InjectionToken<string>(
2222export const CONFIG_DATA : InjectionToken < FormFieldModel > = new InjectionToken < FormFieldModel > ( 'configData' ) ;
2323export const INIT_FORM_VALUES : InjectionToken < any > = new InjectionToken < any > ( 'initFormValues' ) ;
2424export const PARSER_OPTIONS : InjectionToken < ParserOptions > = new InjectionToken < ParserOptions > ( 'parserOptions' ) ;
25+ export const REGEX_FIELD_VALIDATOR : RegExp = new RegExp ( '(\\/?)(.+)\\1([gimsuy]*)' , 'i' ) ;
2526
2627export abstract class FieldParser {
2728
@@ -43,7 +44,7 @@ export abstract class FieldParser {
4344 public abstract modelFactory ( fieldValue ?: FormFieldMetadataValueObject , label ?: boolean ) : any ;
4445
4546 public parse ( ) {
46- if ( ( ( this . getInitValueCount ( ) > 1 && ! this . configData . repeatable ) || ( this . configData . repeatable ) )
47+ if ( ( ( this . getInitValueCount ( ) > 1 && ! this . configData . repeatable ) || ( this . configData . repeatable ) )
4748 && ( this . configData . input . type !== ParserType . List )
4849 && ( this . configData . input . type !== ParserType . Tag )
4950 ) {
@@ -315,6 +316,7 @@ export abstract class FieldParser {
315316 * fields in type bind, made up of a 'match' outcome (make this field visible), an 'operator'
316317 * (OR) and a 'when' condition (the bindValues array).
317318 * @param configuredTypeBindValues array of types from the submission definition (CONFIG_DATA)
319+ * @param typeField
318320 * @private
319321 * @return DynamicFormControlRelation[] array with one relation in it, for type bind matching to show a field
320322 */
@@ -344,7 +346,13 @@ export abstract class FieldParser {
344346 }
345347
346348 protected addPatternValidator ( controlModel ) {
347- const regex = new RegExp ( this . configData . input . regex ) ;
349+ const validatorMatcher = this . configData . input . regex . match ( REGEX_FIELD_VALIDATOR ) ;
350+ let regex ;
351+ if ( validatorMatcher != null && validatorMatcher . length > 3 ) {
352+ regex = new RegExp ( validatorMatcher [ 2 ] , validatorMatcher [ 3 ] ) ;
353+ } else {
354+ regex = new RegExp ( this . configData . input . regex ) ;
355+ }
348356 controlModel . validators = Object . assign ( { } , controlModel . validators , { pattern : regex } ) ;
349357 controlModel . errorMessages = Object . assign (
350358 { } ,
0 commit comments