retrieve label instead of id from a vocabulary

I have defined an vocabulary with the following schema:

<?xml version="1.0"?>
<xs:schema
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:nxsv="http://www.nuxeo.org/ecm/schemas/core/validation/"
    xmlns:ref="http://www.nuxeo.org/ecm/schemas/core/external-references/"
    targetNamespace="de.knipp.nuxeo.currencies">

    <xs:element name="id" type="xs:string"/>
    <xs:element name="label" type="xs:string"/>
    <xs:element name="obsolete" type="xs:integer" default="0"/>
    <xs:element name="ordering" type="xs:integer" default="10000000"/>

</xs:schema>

My test data in CSV format is the following:

id,label,obsolete,ordering
eur,EUR,0,1
centeur,centEUR,0,2
usd,USD,0,3
centusd,centUSD,0,4

Everything works fine: creating and editing my data in the WEBUI.

But when I want to display the value of the data, only the id is displayed (small letters instead of the camel string). I use the following code:

<div role="widget" hidden$="[[!document.properties.rfs:currency]]">
    <label>[[i18n('com.mycompany.nuxeo.richfile.currency')]]</label>
    <div name="currency">[[document.properties.rfs:currency]]</div>
</div>

How can I improve the code above to display the label of the currency?

0 votes

2 answers

102 views

ANSWER



Hello,

You should use the nuxeo-directory-suggestion element for your property so that the ID is resolved with the corresponding label:

<nuxeo-directory-suggestion value="{{document.properties.rfs:currency}}" label="[[i18n('com.mycompany.nuxeo.richfile.currency')]]" min-chars="0" directory-name="<NAME-Of-YOUR-VOCABULARY>" name="currency" role="widget"></nuxeo-directory-suggestion>

Regards

0 votes



If you want the REST API to return the label, you need to define a directoryResolver in your schema (named “rfs” in your case). Explained here: https://doc.nuxeo.com/nxdoc/field-constraints-and-validation/#reference-to-nuxeo-directoryvocabulary-entry

0 votes