diff --git a/backend/src/Squidex.Domain.Apps.Core.Operations/DefaultValues/DefaultValueGenerator.cs b/backend/src/Squidex.Domain.Apps.Core.Operations/DefaultValues/DefaultValueGenerator.cs index a537982c2..f1d7fdce8 100644 --- a/backend/src/Squidex.Domain.Apps.Core.Operations/DefaultValues/DefaultValueGenerator.cs +++ b/backend/src/Squidex.Domain.Apps.Core.Operations/DefaultValues/DefaultValueGenerator.cs @@ -64,15 +64,10 @@ namespace Squidex.Domain.Apps.Core.DefaultValues return; } - if (!fieldData.TryGetValue(partitionKey, out var value) || ShouldApplyDefaultValue(field, value)) + if (!fieldData.TryGetValue(partitionKey, out var value)) { fieldData.AddLocalized(partitionKey, defaultValue); } } - - private static bool ShouldApplyDefaultValue(IField field, IJsonValue value) - { - return value.Type == JsonValueType.Null || (field is IField && value is JsonString s && string.IsNullOrEmpty(s.Value)); - } } } diff --git a/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/DefaultValues/DefaultValuesTests.cs b/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/DefaultValues/DefaultValuesTests.cs index 384643c24..30ac33562 100644 --- a/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/DefaultValues/DefaultValuesTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/DefaultValues/DefaultValuesTests.cs @@ -62,7 +62,7 @@ namespace Squidex.Domain.Apps.Core.Operations.DefaultValues } [Fact] - public void Should_also_enrich_with_default_values_when_string_is_empty() + public void Should_not_enrich_with_default_values_when_string_is_empty() { var data = new ContentData() @@ -75,7 +75,7 @@ namespace Squidex.Domain.Apps.Core.Operations.DefaultValues data.GenerateDefaultValues(schema, languagesConfig.ToResolver()); - Assert.Equal("en-string", data["my-string"]!["de"].ToString()); + Assert.Equal(string.Empty, data["my-string"]!["de"].ToString()); Assert.Equal("en-string", data["my-string"]!["en"].ToString()); } diff --git a/backend/tools/TestSuite/TestSuite.ApiTests/SchemaTests.cs b/backend/tools/TestSuite/TestSuite.ApiTests/SchemaTests.cs index 9a770132b..03e34ade4 100644 --- a/backend/tools/TestSuite/TestSuite.ApiTests/SchemaTests.cs +++ b/backend/tools/TestSuite/TestSuite.ApiTests/SchemaTests.cs @@ -6,6 +6,7 @@ // ========================================================================== using System; +using System.Collections.Generic; using System.Threading.Tasks; using Squidex.ClientLibrary.Management; using TestSuite.Fixtures; @@ -46,6 +47,45 @@ namespace TestSuite.ApiTests Assert.Contains(schemas.Items, x => x.Name == schemaName); } + [Fact] + public async Task Should_create_schema_with_checkboxes() + { + var schemaName = $"schema-{Guid.NewGuid()}"; + + // STEP 1: Create schema + var createRequest = new CreateSchemaDto + { + Name = schemaName, + Fields = new List + { + new UpsertSchemaFieldDto + { + Name = "references", + Partitioning = "invariant", + Properties = new ReferencesFieldPropertiesDto + { + Editor = ReferencesFieldEditor.Checkboxes + } + }, + new UpsertSchemaFieldDto + { + Name = "tags", + Partitioning = "invariant", + Properties = new TagsFieldPropertiesDto + { + Editor = TagsFieldEditor.Checkboxes, + AllowedValues = new List { "value1" } + } + } + } + }; + + var schema = await _.Schemas.PostSchemaAsync(_.AppName, createRequest); + + // Should return created schemas with correct name. + Assert.Equal(schemaName, schema.Name); + } + [Fact] public async Task Should_delete_Schema() { diff --git a/frontend/app/features/content/shared/forms/field-editor.component.html b/frontend/app/features/content/shared/forms/field-editor.component.html index 36aaf5c87..723c836ce 100644 --- a/frontend/app/features/content/shared/forms/field-editor.component.html +++ b/frontend/app/features/content/shared/forms/field-editor.component.html @@ -39,7 +39,7 @@
- +
diff --git a/frontend/app/framework/angular/forms/editors/toggle.component.html b/frontend/app/framework/angular/forms/editors/toggle.component.html index ecdde36e5..51e03c888 100644 --- a/frontend/app/framework/angular/forms/editors/toggle.component.html +++ b/frontend/app/framework/angular/forms/editors/toggle.component.html @@ -1,4 +1,4 @@ -
diff --git a/frontend/app/framework/angular/forms/editors/toggle.component.ts b/frontend/app/framework/angular/forms/editors/toggle.component.ts index bf91f4ce2..6816dbd16 100644 --- a/frontend/app/framework/angular/forms/editors/toggle.component.ts +++ b/frontend/app/framework/angular/forms/editors/toggle.component.ts @@ -46,7 +46,7 @@ export class ToggleComponent extends StatefulControlComponent { /* NOOP */ }; private callTouched = () => { /* NOOP */ }; + private isChecked: boolean | null; + + @Input() + public threeStates = true; constructor( - private readonly element: ElementRef, + private readonly element: ElementRef, private readonly renderer: Renderer2 ) { } - @HostListener('change', ['$event.target.checked']) - public onChange(value: any) { - this.callChange(value); + @HostListener('click') + public onClick() { + let isChecked = this.isChecked; + + if (this.threeStates) { + if (isChecked) { + isChecked = null; + } else if (isChecked === null) { + isChecked = false; + } else { + isChecked = true; + } + } else { + isChecked = !(isChecked === true); + } + + if (isChecked !== this.isChecked) { + this.callChange(isChecked); + } + + this.writeValue(isChecked); } @HostListener('blur') @@ -47,6 +69,8 @@ export class IndeterminateValueDirective implements ControlValueAccessor { this.renderer.setProperty(this.element.nativeElement, 'indeterminate', false); this.renderer.setProperty(this.element.nativeElement, 'checked', obj); } + + this.isChecked = obj; } public setDisabledState(isDisabled: boolean): void {