diff --git a/src/Squidex/app/features/content/pages/content/content-field.component.html b/src/Squidex/app/features/content/pages/content/content-field.component.html
index b8adf3f69..802caaafd 100644
--- a/src/Squidex/app/features/content/pages/content/content-field.component.html
+++ b/src/Squidex/app/features/content/pages/content/content-field.component.html
@@ -31,7 +31,7 @@
@@ -60,6 +60,7 @@
diff --git a/src/Squidex/app/features/content/pages/content/content-page.component.ts b/src/Squidex/app/features/content/pages/content/content-page.component.ts
index dc2c17764..fc0e42533 100644
--- a/src/Squidex/app/features/content/pages/content/content-page.component.ts
+++ b/src/Squidex/app/features/content/pages/content/content-page.component.ts
@@ -270,11 +270,23 @@ export class ContentPageComponent implements CanComponentDeactivate, OnDestroy,
fieldForm.controls['iv'].setValue(fieldValue['iv'] === undefined ? null : fieldValue['iv']);
}
}
-
if (this.content.status === 'Archived') {
this.contentForm.disable();
}
+ } else {
+ for (const field of this.schema.fields) {
+ const defaultValue = field.defaultValue();
+ if (defaultValue) {
+ const fieldForm = this.contentForm.get(field.name);
+ if (field.partitioning === 'language') {
+ for (let language of this.languages) {
+ fieldForm.controls[language.iso2Code].setValue(defaultValue);
+ }
+ } else {
+ fieldForm.controls['iv'].setValue(defaultValue);
+ }
+ }
+ }
}
}
-}
-
+}
\ No newline at end of file
diff --git a/src/Squidex/app/shared/services/schemas.service.spec.ts b/src/Squidex/app/shared/services/schemas.service.spec.ts
index 2f8ec096e..891991edd 100644
--- a/src/Squidex/app/shared/services/schemas.service.spec.ts
+++ b/src/Squidex/app/shared/services/schemas.service.spec.ts
@@ -12,15 +12,18 @@ import {
AddFieldDto,
AnalyticsService,
ApiUrlConfig,
+ AssetsFieldPropertiesDto,
CreateSchemaDto,
createProperties,
DateTime,
+ DateTimeFieldPropertiesDto,
FieldDto,
LocalCacheService,
SchemaDetailsDto,
SchemaDto,
SchemaPropertiesDto,
SchemasService,
+ StringFieldPropertiesDto,
UpdateFieldDto,
UpdateSchemaDto,
UpdateSchemaScriptsDto,
@@ -682,4 +685,34 @@ describe('SchemasService', () => {
req.flush({});
}));
+});
+
+describe('FieldPropertiesDto', () => {
+ it('should return default value for StringFieldProperties', () => {
+ const dto = new StringFieldPropertiesDto(null, null, null, false, false, 'Input', 'Default Value');
+ expect(dto.getDefaultValue()).toEqual('Default Value');
+ });
+
+ it('should return default for DateFieldProperties', () => {
+ const now = DateTime.now();
+ const dto = new DateTimeFieldPropertiesDto(null, null, null, false, false, 'Input', now.toISOString());
+ expect(dto.getDefaultValue()).toEqual(now.toISOString());
+ });
+
+ it('should return calculated date when Today for DateFieldProperties', () => {
+ const now = DateTime.now().date;
+ const dto = new DateTimeFieldPropertiesDto(null, null, null, false, false, 'Input', null, null, null, 'Today');
+ expect(dto.getDefaultValue()).toEqual(now.toUTCStringFormat('ddd, DD MMM YYYY hh:mm:ss Z'));
+ });
+
+ it('should return calculated date when Now for DateFieldProperties', () => {
+ const now = DateTime.now();
+ const dto = new DateTimeFieldPropertiesDto(null, null, null, false, false, 'Input', null, null, null, 'Now');
+ expect(dto.getDefaultValue()).toEqual(now.toUTCStringFormat('ddd, DD MMM YYYY hh:mm:ss Z'));
+ });
+
+ it('should return null for default properties', () => {
+ const dto = new AssetsFieldPropertiesDto(null, null, null, false, false);
+ expect(dto.getDefaultValue()).toEqual(null);
+ });
});
\ No newline at end of file
diff --git a/src/Squidex/app/shared/services/schemas.service.ts b/src/Squidex/app/shared/services/schemas.service.ts
index 0bde5f358..d21777b4e 100644
--- a/src/Squidex/app/shared/services/schemas.service.ts
+++ b/src/Squidex/app/shared/services/schemas.service.ts
@@ -317,6 +317,10 @@ export class FieldDto {
public createValidators(isOptional: boolean): ValidatorFn[] {
return this.properties.createValidators(isOptional);
}
+
+ public defaultValue(): any {
+ return this.properties.getDefaultValue();
+ }
}
export abstract class FieldPropertiesDto {
@@ -333,6 +337,10 @@ export abstract class FieldPropertiesDto {
public abstract formatValue(value: any): string;
public abstract createValidators(isOptional: boolean): ValidatorFn[];
+
+ public getDefaultValue(): any {
+ return null;
+ }
}
export class StringFieldPropertiesDto extends FieldPropertiesDto {
@@ -387,6 +395,10 @@ export class StringFieldPropertiesDto extends FieldPropertiesDto {
return validators;
}
+
+ public getDefaultValue(): any {
+ return this.defaultValue;
+ }
}
export class NumberFieldPropertiesDto extends FieldPropertiesDto {
@@ -426,11 +438,19 @@ export class NumberFieldPropertiesDto extends FieldPropertiesDto {
}
if (this.allowedValues && this.allowedValues.length > 0) {
- validators.push(ValidatorsEx.validValues(this.allowedValues));
+ if (this.isRequired && !isOptional) {
+ validators.push(ValidatorsEx.validValues(this.allowedValues));
+ } else {
+ validators.push(ValidatorsEx.validValues(this.allowedValues.concat([null])));
+ }
}
return validators;
}
+
+ public getDefaultValue(): any {
+ return this.defaultValue;
+ }
}
export class DateTimeFieldPropertiesDto extends FieldPropertiesDto {
@@ -473,6 +493,17 @@ export class DateTimeFieldPropertiesDto extends FieldPropertiesDto {
return validators;
}
+
+ public getDefaultValue(): any {
+ if (this.calculatedDefaultValue != null) {
+ let now = DateTime.now();
+ if (this.calculatedDefaultValue === 'Today') {
+ now = now.date;
+ }
+ return now.toUTCStringFormat('ddd, DD MMM YYYY hh:mm:ss Z');
+ }
+ return this.defaultValue;
+ }
}
export class BooleanFieldPropertiesDto extends FieldPropertiesDto {
@@ -502,6 +533,10 @@ export class BooleanFieldPropertiesDto extends FieldPropertiesDto {
return validators;
}
+
+ public getDefaultValue(): any {
+ return this.defaultValue;
+ }
}
export class GeolocationFieldPropertiesDto extends FieldPropertiesDto {