Browse Source

Fix default value for components.

pull/867/head
Sebastian 4 years ago
parent
commit
ee34a5e9f5
  1. 1
      backend/src/Squidex.Web/Resources.cs
  2. 55
      frontend/src/app/shared/state/contents.forms.spec.ts
  3. 2
      frontend/src/app/shared/state/contents.forms.ts

1
backend/src/Squidex.Web/Resources.cs

@ -179,7 +179,6 @@ namespace Squidex.Web
public Resources(ApiController controller) public Resources(ApiController controller)
{ {
Controller = controller; Controller = controller;
Context = controller.HttpContext.Context(); Context = controller.HttpContext.Context();
} }

55
frontend/src/app/shared/state/contents.forms.spec.ts

@ -559,6 +559,61 @@ describe('ContentForm', () => {
}); });
}); });
it('should add components with default values', () => {
const componentId = MathHelper.guid();
const component = createSchema({
id: 1,
fields: [
createField({
id: 11,
properties: createProperties('String', {
defaultValue: 'Initial',
}),
partitioning: 'invariant',
}),
createField({
id: 12,
properties: createProperties('Number', {
defaultValue: 12,
}),
partitioning: 'invariant',
}),
],
});
const contentForm = createForm([
createField({
id: 4,
properties: createProperties('Components'),
partitioning: 'invariant',
}),
], [], {
[componentId]: component,
});
contentForm.load({});
// Should be undefined by default.
expect(contentForm.value).toEqual({
field4: {
iv: undefined,
},
});
(contentForm.get('field4')?.get('iv') as FieldArrayForm).addComponent(componentId);
// Should add field from component.
expect(contentForm.value).toEqual({
field4: {
iv: [{
schemaId: componentId,
field11: 'Initial',
field12: 12,
}],
},
});
});
it('should replace component with new fields', () => { it('should replace component with new fields', () => {
const component1Id = MathHelper.guid(); const component1Id = MathHelper.guid();
const component1 = createSchema({ const component1 = createSchema({

2
frontend/src/app/shared/state/contents.forms.ts

@ -351,7 +351,7 @@ export class FieldArrayForm extends AbstractContentForm<FieldDto, TemplatedFormA
} }
public addComponent(schemaId: string) { public addComponent(schemaId: string) {
this.form.add().reset({ schemaId }); this.form.add().patchValue({ schemaId });
} }
public addItem() { public addItem() {

Loading…
Cancel
Save