FilterFields issue after upgrading to Litium 6.2

Litium version: [6.2]

I just upgraded my solution to Litium 6.2, and when I tried to run the website, I get errors related to filter fields on accelerator.
First I ended up with
he service ‘Litium.Studio.Accelerator.FieldFramework.FilterJsonFieldTypeConverter’ is not a named server, implementation ‘Litium.Studio.Accelerator.FieldFramework.FilterJsonFieldTypeConverter’ should not have [Service(Name = “FilterFields”)] attribute.

I removed this and ended up with other.
Could I get some help to fix this issue?

The IJsonFieldTypeConverter is depricated and is not at all used from 6.2. We have introduced some new proeprties and methods on the field type directly, see https://docs.litium.com/support/bugs/bug_details?id=41872

To find the latest source for the filter field type is to download the updated Accelerator where you can compare and copy the updated code into your solution.

For the filter field type the class should be

using System;
using System.Collections.Generic;
using System.Linq;
using Litium.ComponentModel;
using Litium.FieldFramework;

namespace Litium.Accelerator.FieldTypes
{
    public class FilterFieldTypeMetadata : FieldTypeMetadataBase
    {
        public override string Id => "FilterFields";
        public override bool IsArray => true;
        public override Type JsonType => typeof(List<string>);
        public override Type OptionType => typeof(Option);

        public override IFieldType CreateInstance(IFieldDefinition fieldDefinition)
        {
            var item = new FilterFieldType();
            item.Init(fieldDefinition);
            return item;
        }

        public class FilterFieldType : FieldTypeBase
        {
            private Option _option;

            public override object GetValue(ICollection<FieldData> fieldDatas)
            {
                if (fieldDatas.Count == 1 && fieldDatas.First().BooleanValue.HasValue)
                {
                    return null;
                }

                return fieldDatas.Where(x => !string.IsNullOrEmpty(x.TextValue)).Select(x => x.TextValue).ToList();
            }

            public override void Init(IFieldDefinition fieldDefinition)
            {
                base.Init(fieldDefinition);
                _option = fieldDefinition.Option as Option ?? new Option();
            }

            public override ICollection<FieldData> PersistFieldData(object item)
            {
                return PersistFieldDataInternal(item);
            }

            protected override ICollection<FieldData> PersistFieldDataInternal(object item)
            {
                var data = item as IEnumerable<string>;
                if (data == null)
                {
                    return new[] { new FieldData { BooleanValue = true } };
                }

                return data.Select(x => new FieldData { TextValue = x }).ToList();
            }

            public override object ConvertFromJsonValue(object item)
            {
                return item as IList<string>;
            }

            public override object ConvertToJsonValue(object item)
            {
                var items = item as IList<string>;

                if (items == null && item is string value)
                {
                    items = new List<string> { value };
                }

                return items;
            }
        }

        public class Option : ObjectBase
        {
            private IList<string> _items = new List<string>();

            public virtual IList<string> Items
            {
                get => _items;
                set => _items = this.ThrowIfReadOnly(value);
            }
        }
    }
}
1 Like