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

927 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



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

I have done two minor changes, which should not have influence on the described problem. I added a readonly attribute (changes should not be possible during displaying) and a hidden attribute (to hide the value if it is not defined at all).

But the problem persists. Here is my fragment from my nuxeo-file-metadata-layout.html:

&lt;nuxeo-directory-suggestion
  hidden$=&quot;[[!document.properties.rfs:currency]]&quot;
  readonly=&quot;&quot;   
  value=&quot;{{document.properties.rfs:currency}}&quot;
  label=&quot;[[i18n(&apos;com.mycompany.nuxeo.richfile.currency&apos;)]]&quot;
  min-chars=&quot;0&quot;
  directory-name=&quot;currency&quot;
  name=&quot;currency&quot;
  role=&quot;widget&quot;/&gt;

And when I enter the edit mode again, the key and not the label is display. BTW: The correct key is stored in the database (I have checed in the DB) and the correct key is displayed. So it is not a problem wrong data or anything else.

04/02/2022


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



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

Surprisingly your solution in combination with Gregories answer works!

Surprisingly, because in my understanding your hint only ensures the integrity of the data, using the directoryResoler as field constrain. My data is already valid. It has nothing to do with the display of the already valid data.

It seems that I have not understood some basics. :-( If you like, you can point me to an explanation.

But again, many thanks.

04/02/2022