挂钩到项目选择动作



当我选择一个项目时,我想在字段编辑器中显示某些字段,然后在其他字段上更改值。

因此,我需要订阅一个事件,但是我可以看到此事件并不存在。有没有一种方法可以连接项目选择操作,或者我需要创建一个自定义事件,如果是的话 - 我需要在哪里提出?

听起来您需要创建一个自定义验证器 - 此博客文章描述了该过程:https://www.habaneroconsulting.com/stories/insights/2016/creating-a-custom-field-validator-in-sitecore

总结:

创建一个新的字段规则(字段验证器位于/sitecore/system/satectings/settings/validation/validation/field ulud/field规则/中(,链接到您的汇编。上面的博客文章给出了字段验证器的以下示例

[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);
        }
    }
}

信用:迈克尔·阿姆斯特朗

最新更新