Default value for CMS field

How do you define a default value for a field (text/numeric) used on a Page or Block in Litium 8?

Litium version: 8.11.0

I don’t know another simpler way then validators. in below case it is a boolean field but it works the same way for text and numbers. If you don’t want to set the default text if some one actually removed the value you can use validationmode to se if the entity is added (new) or modified (Old)

public override ValidationResult Validate(DraftPage entity, ValidationMode validationMode)
        {
            var result = new ValidationResult();
            var eventTemplate = _fieldTemplateService.Get<Litium.Websites.FieldTemplateBase>(PageTemplateNameConstants.ProjectList);

            if (validationMode != ValidationMode.Add) return result;

            if (entity.FieldTemplateSystemId != eventTemplate.SystemId) return result;

            if (entity.Fields.GetValue<bool?>(PageFieldNameConstants.ShowFinishedProjects) == null)
            {
                entity.Fields.AddOrUpdateValue(PageFieldNameConstants.ShowFinishedProjects, false);
            }

            return result;
        }

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.