cancel
Showing results for 
Search instead for 
Did you mean: 

retrieve label instead of id from a vocabulary

ElmarKnipp_
Confirmed Champ
Confirmed Champ

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?

4 REPLIES 4

Benjamin_Gamar1
Champ in-the-making
Champ in-the-making

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...

Benjamin, thanks for your response (and sorry for the late response).

Gregory_Carlin
Elite Collaborator
Elite Collaborator

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

Gregory, thanks for your answer (and sorry for the late response).

Getting started

Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.