Действие для выбора элемента - PullRequest
0 голосов
/ 23 июня 2019

Когда я выбираю элемент, я хочу проверить некоторые поля, прежде чем он будет отображаться в редакторе полей, а затем изменить значения в других полях.

Так что мне нужно подписаться на событие, но такого события не существует, как я вижу. Есть ли способ привязать действие выбора элемента или мне нужно создать собственное событие, если так - где мне нужно его вызвать?

1 Ответ

0 голосов
/ 27 июня 2019

Похоже, вам нужно создать собственный валидатор - этот пост в блоге описывает процесс: https://www.habaneroconsulting.com/stories/insights/2016/creating-a-custom-field-validator-in-sitecore

В итоге:

Создайте новое правило поля (валидаторы поля расположены в / sitecore / system / Settings / Validation Rules / Field Rules / ), ссылающиеся на вашу сборку.В сообщении блога выше приведен следующий пример валидатора поля

[Serializable]
namespace MySitecore.Project.Validators
{
    // This validator ensures that the description attribute of a link is specified
    public class LinkTextValidator : StandardValidator
    {
        public override string Name
        {
            get { return "Link text validator"; }
        }

        public LinkTextValidator() {}

        public LinkTextValidator(SerializationInfo info, StreamingContext context) : base(info, context) { }

        protected override ValidatorResult Evaluate()
        {
            Field field = this.GetField();
            if (field == null)
                return ValidatorResult.Valid;

            string str1 = this.ControlValidationValue;
            if (string.IsNullOrEmpty(str1) || string.Compare(str1, "<link>", StringComparison.InvariantCulture) == 0)
                return ValidatorResult.Valid;

            XmlValue xmlValue = new XmlValue(str1, "link");
            string attribute = xmlValue.GetAttribute("text");
            if (!string.IsNullOrEmpty(xmlValue.GetAttribute("text")))
                return ValidatorResult.Valid;

            this.Text = this.GetText("Description is missing in the link field \"{0}\".", field.DisplayName);
            // return the failed result value defined in the parameters for this validator; if no Result parameter
            // is defined, the default value FatalError will be used
            return this.GetFailedResult(ValidatorResult.CriticalError);
        }

        protected override ValidatorResult GetMaxValidatorResult()
        {
            return this.GetFailedResult(ValidatorResult.Error);
        }
    }
}

Кредит: MICHAEL ARMSTRONG

...