Limit number of Characters entered for Link Title Field in General Link

一世执手 提交于 2019-12-11 21:27:31

问题


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

Thanks in Advance,


回答1:


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" />

Edit: new solution to enable per template-field maxlength

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"/>

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

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.

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



来源:https://stackoverflow.com/questions/23420527/limit-number-of-characters-entered-for-link-title-field-in-general-link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!