Pregunta

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

enter image description here

Thanks in Advance,

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top