6

Apart from Event System C# Coding, is there any other simple way which allows to put a restriction on Field Value of an RTF field (or rather complex types like maximum number of linked component in a component link type field)?

To define the business requirement: we have requirement where we want to put up restriction on maximum number of component being linked in a field and additionally for RTF fields, we need put a max length validation.

1 Answer 1

6

RTF fields are complicated to limit in length because it's not easy to calculate how many characters are actual text and how many are tags. There's a few libraries out there that help with it, but the logic is too complex to implement in anything other than Event System or - if you're feeling bullish - Anguilla.

Min and Max occurrences can be set quite easily in the XSD, and these apply to any multivalue field - including component links.

I did some research on this with Robert Curlette, you can find part 1 here and part 2 here. There is also a pretty good chapter on LiveContent about schema constraints (requires login).

4
  • Thanks Nuno for your input and to confirm that it is not possible without coding in C#. Convincing the client is tough as anything that got changed outside the CMS will require a build and has to go through full SDLC and your inputs will definitely make it easier for me. Commented Jun 5, 2013 at 10:49
  • You could probably implement easily a Publishing restriction instead, so that only X characters from an RTF field get published. I did it recently with this code: robvolk.com/truncate-html-string-c-extension-method
    – Nuno Linhares
    Commented Jun 5, 2013 at 11:03
  • Be careful with setting Min and Max occurrences in your Schema, while this is valid according to W3C, the UI doesn't fully understand it. When you edit the Schema afterwards your values might not be retained (it only expects value like 0, 1 or unbounded). Commented Jun 5, 2013 at 12:08
  • The CME - as from 2011 - copes well with other values too. Give it a try.
    – Nuno Linhares
    Commented Jun 5, 2013 at 12:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.