Hello everyone!
How can I set the width of EntityCombobox component’s options list? I need it not to expand if some of the options are too long.
I want the options to be truncated if they are too long.
Hello Evgen!
Unfortunately ComboBox
does not provide API for limiting width of popup. However you can manually truncate text that exceed some limits.
For instance, add optionCaptionProvider
:
@Autowired
private MetadataTools metadataTools;
@Install(to = "entityComboBox", subject = "optionCaptionProvider")
private String entityComboBoxOptionCaptionProvider(final User user) {
String instanceName = metadataTools.getInstanceName(user);
if (instanceName.length() > 30) {
instanceName = instanceName.substring(0, 30) + "...";
}
return instanceName;
}
Thank you Roman. As far as I know, there is still a method for setting the ComboBox extension using the setPopupWidth method. It was very helpful for me at some points.
But now I have another question.
The ComboBox has an attribute called pageLength which produces a scrollbar to the combobox.
I need an analogue of such an attribute, but the valuesPicker uses a property that uses useComboBox. In general, I can’t figure out how to add a scrollbar to the dropdown list if it is opened from the ValuesPicker
To change some properties of generated components in “Select dialog” you should provide your custom implementation of this dialog.
ValuesSelectAction
supports setting custom “Select dialog”. You can extend existing SelectValueDialog
screen using “Extend an existing screen” template in “Create Jmix screen” dialog.
For instance:
@UiController("ext_selectValueDialog")
@UiDescriptor("ext-select-value-dialog.xml")
public class ExtSelectValueDialog extends SelectValueDialog {
@Override
protected Field createEntityComboBox(MetaClass metaClass) {
EntityComboBox entityComboBox = (EntityComboBox) super.createEntityComboBox(metaClass);
entityComboBox.setPageLength(2);
return entityComboBox;
}
}
In the action you should define a selectValueScreenId
property:
<valuesPicker ...>
<actions>
<action id="valuesSelect" type="values_select">
<properties>
...
<property name="selectValueScreenId" value="ext_selectValueDialog"/>
</properties>
</action>
</actions>
</valuesPicker>