mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-09 19:13:08 +00:00
[1950] [DURACOM-101] Regex validator improved
feat: - New regexp to validate pattern used for regex validation;
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import {Inject, InjectionToken} from '@angular/core';
|
import { Inject, InjectionToken } from '@angular/core';
|
||||||
|
|
||||||
import uniqueId from 'lodash/uniqueId';
|
import { uniqueId } from 'lodash';
|
||||||
import {DynamicFormControlLayout, DynamicFormControlRelation, MATCH_VISIBLE, OR_OPERATOR} from '@ng-dynamic-forms/core';
|
import { DynamicFormControlLayout, DynamicFormControlRelation, MATCH_VISIBLE, OR_OPERATOR } from '@ng-dynamic-forms/core';
|
||||||
|
|
||||||
import { hasValue, isNotEmpty, isNotNull, isNotUndefined } from '../../../empty.util';
|
import { hasValue, isNotEmpty, isNotNull, isNotUndefined } from '../../../empty.util';
|
||||||
import { FormFieldModel } from '../models/form-field.model';
|
import { FormFieldModel } from '../models/form-field.model';
|
||||||
@@ -22,6 +22,7 @@ export const SUBMISSION_ID: InjectionToken<string> = new InjectionToken<string>(
|
|||||||
export const CONFIG_DATA: InjectionToken<FormFieldModel> = new InjectionToken<FormFieldModel>('configData');
|
export const CONFIG_DATA: InjectionToken<FormFieldModel> = new InjectionToken<FormFieldModel>('configData');
|
||||||
export const INIT_FORM_VALUES: InjectionToken<any> = new InjectionToken<any>('initFormValues');
|
export const INIT_FORM_VALUES: InjectionToken<any> = new InjectionToken<any>('initFormValues');
|
||||||
export const PARSER_OPTIONS: InjectionToken<ParserOptions> = new InjectionToken<ParserOptions>('parserOptions');
|
export const PARSER_OPTIONS: InjectionToken<ParserOptions> = new InjectionToken<ParserOptions>('parserOptions');
|
||||||
|
export const REGEX_FIELD_VALIDATOR: RegExp = new RegExp('(\\/?)(.+)\\1([gimsuy]*)', 'i');
|
||||||
|
|
||||||
export abstract class FieldParser {
|
export abstract class FieldParser {
|
||||||
|
|
||||||
@@ -43,7 +44,7 @@ export abstract class FieldParser {
|
|||||||
public abstract modelFactory(fieldValue?: FormFieldMetadataValueObject, label?: boolean): any;
|
public abstract modelFactory(fieldValue?: FormFieldMetadataValueObject, label?: boolean): any;
|
||||||
|
|
||||||
public parse() {
|
public parse() {
|
||||||
if (((this.getInitValueCount() > 1 && !this.configData.repeatable) || (this.configData.repeatable))
|
if (((this.getInitValueCount() > 1 && !this.configData.repeatable) || (this.configData.repeatable))
|
||||||
&& (this.configData.input.type !== ParserType.List)
|
&& (this.configData.input.type !== ParserType.List)
|
||||||
&& (this.configData.input.type !== ParserType.Tag)
|
&& (this.configData.input.type !== ParserType.Tag)
|
||||||
) {
|
) {
|
||||||
@@ -315,6 +316,7 @@ export abstract class FieldParser {
|
|||||||
* fields in type bind, made up of a 'match' outcome (make this field visible), an 'operator'
|
* fields in type bind, made up of a 'match' outcome (make this field visible), an 'operator'
|
||||||
* (OR) and a 'when' condition (the bindValues array).
|
* (OR) and a 'when' condition (the bindValues array).
|
||||||
* @param configuredTypeBindValues array of types from the submission definition (CONFIG_DATA)
|
* @param configuredTypeBindValues array of types from the submission definition (CONFIG_DATA)
|
||||||
|
* @param typeField
|
||||||
* @private
|
* @private
|
||||||
* @return DynamicFormControlRelation[] array with one relation in it, for type bind matching to show a field
|
* @return DynamicFormControlRelation[] array with one relation in it, for type bind matching to show a field
|
||||||
*/
|
*/
|
||||||
@@ -344,7 +346,13 @@ export abstract class FieldParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected addPatternValidator(controlModel) {
|
protected addPatternValidator(controlModel) {
|
||||||
const regex = new RegExp(this.configData.input.regex);
|
const validatorMatcher = this.configData.input.regex.match(REGEX_FIELD_VALIDATOR);
|
||||||
|
let regex;
|
||||||
|
if (validatorMatcher != null && validatorMatcher.length > 3) {
|
||||||
|
regex = new RegExp(validatorMatcher[2], validatorMatcher[3]);
|
||||||
|
} else {
|
||||||
|
regex = new RegExp(this.configData.input.regex);
|
||||||
|
}
|
||||||
controlModel.validators = Object.assign({}, controlModel.validators, { pattern: regex });
|
controlModel.validators = Object.assign({}, controlModel.validators, { pattern: regex });
|
||||||
controlModel.errorMessages = Object.assign(
|
controlModel.errorMessages = Object.assign(
|
||||||
{},
|
{},
|
||||||
|
Reference in New Issue
Block a user