Hi
I’d like to create field with label like in currency field. I want to use this to quantity field, because I’d like show value and unit e.g 10 pcs.
Is there any way create custom component using mechanism ComponentGenerationStrategy ?
Hi
I’d like to create field with label like in currency field. I want to use this to quantity field, because I’d like show value and unit e.g 10 pcs.
Is there any way create custom component using mechanism ComponentGenerationStrategy ?
Hello Andrezj,
i use the following function for generating a “Currency Field”:
private HBoxLayout generateCurrencyTextField (Datasource datasource, String fieldId,
String datasourceAttrb, String textFieldId) {
HBoxLayout hBox = componentsFactory.createComponent(HBoxLayout.class);
hBox.setSpacing(true);
hBox.setWidth("100%");
TextField textField = componentsFactory.createComponent(TextField.class);
textField.setDatasource(datasource, datasourceAttrb);
textField.setStyleName("align-right");
textField.setId(textFieldId);
textField.setRequired(true);
hBox.add(textField);
hBox.expand(textField);
Label currencyLabel = componentsFactory.createComponent(Label.class);
currencyLabel.setAlignment(Alignment.MIDDLE_CENTER);
currencyLabel.setValue("€");
hBox.add(currencyLabel);
return hBox;
}
And the generator of the FieldGroup Field looks like follows:
public Component generateFIELD(Datasource datasource, String fieldId) {
return generateCurrencyTextField (datasource, fieldId, "ID of the datasource column", "ID of the generated text field");
}
And BTW, as far as i know, with one of the latest CUBA Versions, there is actually a “Currency Text Field” functionality.