限制在常规链接中为“链接标题字段”输入的字符数 [英] Limit number of Characters entered for Link Title Field in General Link

查看:332
本文介绍了限制在常规链接中为“链接标题字段”输入的字符数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以限制内容作者可以在链接标题字段中为内部和外部链接的常规链接输入的字符数量,如下所示

Can we limit number of characters that a content author can enter in the Link Title Field for general link for both Internal and External Link as shown below

谢谢提前,

推荐答案

我还没有找到一种方法来设置每个模板字段,但我设法添加MaxLength此文件中的输入:sitecore\shell\Applications \Dialogs \ExternalLink \ExternalLink.xml

I have yet to find a way to set this per template-field but I managed to add a MaxLength on the input in this file: sitecore\shell\Applications\Dialogs\ExternalLink\ExternalLink.xml

<Edit ID="Title" Width="100%" MaxLength="20" />

编辑:启用每个模板字段maxlength的新解决方案

new solution to enable per template-field maxlength

我进一步挖掘并发现了一种类似的方法来操纵这种行为。在同一个xml文件中,您可以将codebeside类设置为您自己的类:

I dug a bit further and found a similar way to manipulate this behavior. In the same xml file you can set the codebeside class to one of your own:

  <!--original value: <CodeBeside Type="Sitecore.Shell.Applications.Dialogs.ExternalLink.ExternalLinkForm,Sitecore.Client"/>-->
  <CodeBeside Type="SitecoreMvc.Shell.Applications.Dialogs.ExternalLink.CustomExternalLinkForm,SitecoreMvc"/>

然后在我的CustomExternalLinkForm类中,我重写Onload方法并添加一些逻辑:

Then in my CustomExternalLinkForm class I override the Onload method and add some logic like so:

public class CustomExternalLinkForm : Sitecore.Shell.Applications.Dialogs.ExternalLink.ExternalLinkForm
{
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        var ro = WebUtil.ParseQueryString(WebUtil.GetQueryString("ro"));

        int titleMaxLength;
        if (int.TryParse(ro["maxTitleLength"], out titleMaxLength)) 
            Title.Attributes.Add("MaxLength", titleMaxLength.ToString());
    }
}

roQs参数是Sitecore已经通过的并且内容是当前字段的字段源中填充的内容。所以这实际上可以让你做更多的扩展。

The "ro" Qs parameter is something Sitecore already passes and the contents is that what is filled in the field source of the current field. So this does actually enables you to do some more extending.

不是最优雅的解决方案,因为你必须编辑sitecore shell文件,但它可以工作。

Not the most elegant solution because you have to edit sitecore shell files, but it works.

这篇关于限制在常规链接中为“链接标题字段”输入的字符数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆