[SOLVED] Plone supermodel XML with inline key-value pairs

The element element inside a supermodel XML allows us to specify the value of a vocabulary.

However is is possible to define the token separately from the title?

  <field name="type-activiteit" type="zope.schema.Choice" easyform:validators="" easyform:THidden="">
                              <description>Het soort activiteit wordt enkel hier vermeld (niet in de titel). Zo kunnen bezoekers een selectie maken op de verschillende types (bv. alle lezingen).</description>
                              <title>Soort activiteit</title>
 <element>|--Kies een optie--</element>
                  <element>Academische zitting</element>


The reason is PFG -> EasyForm migration where collective.jsonify exports a vocabulary as

    "fgVocabulary": [

... and this has to be mapped somehow into the supermodel XML.

registry.xml lets you do this...

  <record name='mdb_theme.ColorTypeList'>
      <field type='plone.registry.field.Dict'>
        <title>Custom color name types</title>
        <description>(token, translationmessage)</description>
        <key_type name='key' type='plone.registry.field.ASCIILine'>
          <title>unique id (token)</title>
        <value_type name='value' type='plone.registry.field.TextLine'>
          <title>value (title)</title>
      <value purge="False">
        <element key='colorlist_pnz_default'>Nur PNZ Standard Farben</element>
        <element key='colorlist_pnz_czech'>Powered by PNZ - Tsjechei</element>
1 Like

It might be enough to just add 'key':

<element key="a">Academische zitting</element>

I'd guess you have to define field as a zope.schema.Dict and give it names for key_type and value_type as well.

I tried something… not sure if it is of any use:

Using the key attribute works. SOLVED

you're right :muscle:

both single and multiple choice fields can use a key/value pair:

    <field name="multiple_choice" type="zope.schema.Set">
      <title>multiple choice</title>
      <value_type type="zope.schema.Choice">
          <element key="aaa">choice 1</element>
          <element key="bbb">choice 2</element>
    <field name="single_choice" type="zope.schema.Choice">
      <title>single choice</title>
          <element key="aaa">choice 1</element>
          <element key="bbb">choice 2</element>
1 Like