15

In the documentation I read that it is possible to constrain field content of single-line text fields, number fields and date fields. But how exactly do I do that?

My (simplified) Schema looks like this:

<xsd:schema xmlns="uuid:2b" xmlns:tcmi="http://www.tridion.com/ContentManager/5.0/Instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="uuid:2b">
  <xsd:import namespace="http://www.tridion.com/ContentManager/5.0/Instance"></xsd:import>
  <xsd:annotation>
    <xsd:appinfo>
      <tcm:Labels xmlns:tcm="http://www.tridion.com/ContentManager/5.0">
        <tcm:Label ElementName="tag" Metadata="false">Tag</tcm:Label>
      </tcm:Labels>
    </xsd:appinfo>
  </xsd:annotation>
  <xsd:element name="Content">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="tag" minOccurs="1" maxOccurs="unbounded" type="xsd:normalizedString">
          <xsd:annotation>
            <xsd:appinfo>
              <tcm:ExtensionXml xmlns:tcm="http://www.tridion.com/ContentManager/5.0"></tcm:ExtensionXml>
            </xsd:appinfo>
          </xsd:annotation>
        </xsd:element>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

So how would I set a maximum length of 15 characters on the tag field?

17

Constraining field content describes constraining field content with the use of facets. Facets constrain the properties of a field type, so you will have to adjust the type definition of your Schema field.

Take your current field definition in your Schema

<xsd:element name="tag" minOccurs="1" maxOccurs="unbounded" type="xsd:normalizedString">
  <xsd:annotation>
    <xsd:appinfo>
      <tcm:ExtensionXml xmlns:tcm="http://www.tridion.com/ContentManager/5.0"></tcm:ExtensionXml>
    </xsd:appinfo>
  </xsd:annotation>
</xsd:element>

Now change that to this (in the Schema source tab):

<xsd:element name="tag" minOccurs="1" maxOccurs="unbounded">
  <xsd:annotation>
    <xsd:appinfo>
      <tcm:ExtensionXml xmlns:tcm="http://www.tridion.com/ContentManager/5.0"></tcm:ExtensionXml>
    </xsd:appinfo>
  </xsd:annotation>
  <xsd:simpleType>
    <xsd:restriction base="xsd:normalizedString">
      <xsd:maxLength value="15"/>
    </xsd:restriction> 
  </xsd:simpleType>
</xsd:element>

As you can see, you moved the type attribute into a child element xsd:simpleType, in which you added the restriction (or constraint).

11

Some constraints - maxLength, or min|maxOccurs - are handled really well by the CME.

Other constraints may get a really hard to understand error message: XML Validation Failed Error message

You may want to test this before just rolling it out to your editors. Max length, if I'm not mistaken, will simply not allow you to type any more characters once the limit is reached. I did some research on ways to notify editors about field limitations, available here and here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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