mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-13 04:53:06 +00:00
[1950][DURACOM-101] JSDoc and regex validation tests
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
import { Inject, InjectionToken } from '@angular/core';
|
||||
|
||||
import uniqueId from 'lodash/uniqueId';
|
||||
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 { FormFieldModel } from '../models/form-field.model';
|
||||
@@ -22,6 +27,11 @@ export const SUBMISSION_ID: InjectionToken<string> = new InjectionToken<string>(
|
||||
export const CONFIG_DATA: InjectionToken<FormFieldModel> = new InjectionToken<FormFieldModel>('configData');
|
||||
export const INIT_FORM_VALUES: InjectionToken<any> = new InjectionToken<any>('initFormValues');
|
||||
export const PARSER_OPTIONS: InjectionToken<ParserOptions> = new InjectionToken<ParserOptions>('parserOptions');
|
||||
/**
|
||||
* This pattern checks that a regex field uses the common ECMAScript format: `/{pattern}/{flags}`, in which the flags
|
||||
* are part of the regex, or a simpler one with only pattern `/{pattern}/` or `{pattern}`.
|
||||
* The regex itself is encapsulated inside a `RegExp` object, that will validate the pattern syntax.
|
||||
*/
|
||||
export const REGEX_FIELD_VALIDATOR = new RegExp('(\\/?)(.+)\\1([gimsuy]*)', 'i');
|
||||
|
||||
export abstract class FieldParser {
|
||||
@@ -345,6 +355,13 @@ export abstract class FieldParser {
|
||||
return hasValue(this.configData.input.regex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds pattern validation to `controlModel`, it uses the encapsulated `configData` to test the regex,
|
||||
* contained in the input config, against the common `ECMAScript` standard validator {@link REGEX_FIELD_VALIDATOR},
|
||||
* and creates an equivalent `RegExp` object that will be used during form-validation against the user-input.
|
||||
* @param controlModel
|
||||
* @protected
|
||||
*/
|
||||
protected addPatternValidator(controlModel) {
|
||||
const validatorMatcher = this.configData.input.regex.match(REGEX_FIELD_VALIDATOR);
|
||||
let regex;
|
||||
|
Reference in New Issue
Block a user