mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
Added support for regex validation
This commit is contained in:
@@ -168,6 +168,11 @@
|
||||
"group-collapse": "Collapse",
|
||||
"group-expand": "Expand",
|
||||
"group-collapse-help": "Click here to collapse",
|
||||
"group-expand-help": "Click here to expand and add more element"
|
||||
"group-expand-help": "Click here to expand and add more element",
|
||||
"error": {
|
||||
"validation": {
|
||||
"pattern": "This input is restricted by the current pattern: {{ pattern }}."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -333,7 +333,7 @@
|
||||
[ngClass]="getClass('element', 'hint')"></small>
|
||||
|
||||
<div *ngIf="showErrorMessages" [ngClass]="[getClass('element', 'errors'), getClass('grid', 'errors')]">
|
||||
<small *ngFor="let message of errorMessages" class="invalid-feedback d-block">{{ message }}</small>
|
||||
<small *ngFor="let message of errorMessages" class="invalid-feedback d-block">{{ message | translate:model.validators }}</small>
|
||||
</div>
|
||||
|
||||
</ng-container>
|
||||
|
@@ -156,7 +156,7 @@ export class FormBuilderService extends DynamicFormService {
|
||||
Object.keys(groupValue)
|
||||
.forEach((key) => {
|
||||
const normValue = normalizeValue(controlModel, groupValue[key], groupIndex);
|
||||
if (normValue.hasValue()) {
|
||||
if (isNotEmpty(normValue) && normValue.hasValue()) {
|
||||
if (iterateResult.hasOwnProperty(key)) {
|
||||
iterateResult[key].push(normValue);
|
||||
} else {
|
||||
|
@@ -26,6 +26,7 @@ export class FormFieldModel {
|
||||
@autoserialize
|
||||
input: {
|
||||
type: string;
|
||||
regex?: string;
|
||||
};
|
||||
|
||||
@autoserialize
|
||||
|
@@ -194,6 +194,11 @@ export abstract class FieldParser {
|
||||
this.markAsRequired(controlModel);
|
||||
}
|
||||
|
||||
if (this.hasRegex()) {
|
||||
console.log(this.configData.input.regex);
|
||||
this.addPatternValidator(controlModel);
|
||||
}
|
||||
|
||||
// Available Languages
|
||||
if (this.configData.languageCodes && this.configData.languageCodes.length > 0) {
|
||||
(controlModel as DsDynamicInputModel).languageCodes = this.configData.languageCodes;
|
||||
@@ -202,6 +207,20 @@ export abstract class FieldParser {
|
||||
return controlModel;
|
||||
}
|
||||
|
||||
protected hasRegex() {
|
||||
return hasValue(this.configData.input.regex);
|
||||
}
|
||||
|
||||
protected addPatternValidator(controlModel) {
|
||||
const regex = new RegExp(this.configData.input.regex);
|
||||
controlModel.validators = Object.assign({}, controlModel.validators, {pattern: regex});
|
||||
controlModel.errorMessages = Object.assign(
|
||||
{},
|
||||
controlModel.errorMessages,
|
||||
{pattern: 'form.error.validation.pattern', regex: 'form.error.validation.pattern'});
|
||||
|
||||
}
|
||||
|
||||
protected markAsRequired(controlModel) {
|
||||
controlModel.required = true;
|
||||
controlModel.validators = Object.assign({}, controlModel.validators, {required: null});
|
||||
|
@@ -71,7 +71,10 @@ describe('RowParser test suite', () => {
|
||||
row2 = {
|
||||
fields: [
|
||||
{
|
||||
input: {type: 'onebox'},
|
||||
input: {
|
||||
type: 'onebox',
|
||||
regex: '^[a-zA-Z0-9]+$'
|
||||
},
|
||||
label: 'Title',
|
||||
mandatory: 'false',
|
||||
repeatable: true,
|
||||
|
@@ -122,14 +122,8 @@ export class NumberPickerComponent implements OnInit, ControlValueAccessor {
|
||||
}
|
||||
|
||||
writeValue(value) {
|
||||
if (this.startValue) {
|
||||
this.startValue = this.value;
|
||||
this.value = value;
|
||||
} else {
|
||||
// First init
|
||||
this.startValue = value || this.min;
|
||||
}
|
||||
}
|
||||
|
||||
registerOnChange(fn) {
|
||||
return
|
||||
|
Reference in New Issue
Block a user