public static ArrayFieldItem CreateArrayField(this ArrayFieldOptions options)
        {
            ArrayFieldItem item = new ArrayFieldItem();

            ApplySchema(item, options);

            return(item);
        }
        public static TContentItem AddArrayFieldItem <TContentItem>(this TContentItem contentItem, string name, IContentSchema schema, Action <ArrayFieldItem> action)
            where TContentItem : IContentElement
        {
            ArrayFieldOptions options = schema.GetArrayFieldOptions(name);
            ArrayFieldItem    item    = options.CreateArrayField();

            action(item);

            return(AddArrayFieldItem(contentItem, name, item));
        }
        public static TContentSchema AddArray <TContentSchema>(this TContentSchema schema, string name, Action <ArrayFieldOptions>?configOptions = null)
            where TContentSchema : IContentSchema
        {
            ArrayFieldOptions options = new ArrayFieldOptions();

            configOptions?.Invoke(options);

            schema.AddField <ArrayField>(name, options, null);

            return(schema);
        }
Beispiel #4
0
        public override void Validate(string fieldName, ContentFieldOptions options, ValidationContext context)
        {
            ArrayFieldOptions fieldOptions = (ArrayFieldOptions)options;

            if (fieldOptions.IsRequired && Items.Any() == false)
            {
                context.AddRequireValidation(fieldName);
            }

            if (Items.Count < fieldOptions.MinItems || Items.Count > fieldOptions.MaxItems)
            {
                context.AddRangeValidation(fieldName, fieldOptions.MinItems, fieldOptions.MaxItems);
            }
        }