Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
How to implement isRequired in a Label
Dear all
I have created a component (see attachment) and I need to add isRequired method.
But the idea is when I set "true" I want to show a " * "
by default Label does not implement this
any idea help are welcome
Thanks to all.
What is the component in the picture? Do you mean that it is a CustomComponent composite?
You could instead use CustomField for composition, which has the required property, or just use CSS to show the indicator, as suggested here for Table.
Marko Grönroos: What is the component in the picture? Do you mean that it is a CustomComponent composite?
You could instead use CustomField for composition, which has the required property, or just use CSS to show the indicator, as suggested here for Table.
Yes it is a CustomComponent composite, and I would like to add isRequired to my component
I have to add a " * " to my Label
Because setRequired add new Tag span and I try to do it but is not working
Marko Grönroos: What is the component in the picture? Do you mean that it is a CustomComponent composite?
You could instead use CustomField for composition, which has the required property, or just use CSS to show the indicator, as suggested here for Table.
I try to do this
if(getState().required)
{
SpanElement span = Document.get().createSpanElement();
span.setInnerText("*");
span.setClassName("v-required-field-indicator");
getWidget().getElement().appendChild(span);
}
but not working
I'm now getting confused. That code is client-side code, but you said you have made a CustomComponent, which is used for composition on the server-side.
If you are working with a client-side widget, it gets more complicated, as the indicator is part of the component caption, which is usually handled in the containing layout.
Is the whole of the screenshot your component or is your component only a part of it?
Should it be the whole thing - then I assume that your Label is "Document Model"? If so why not instead set "Document Model" as caption for the ComboBox and set the ComboBox as required - or would that mess up your business logic?
Peter Stockinger: Is the whole of the screenshot your component or is your component only a part of it?
Should it be the whole thing - then I assume that your Label is "Document Model"? If so why not instead set "Document Model" as caption for the ComboBox and set the ComboBox as required - or would that mess up your business logic?
Yes my Label is "Document Model", I don't use ComboBox, I use a Panel because I need to have the control on all item inside
Marko Grönroos: I'm now getting confused. That code is client-side code, but you said you have made a CustomComponent, which is used for composition on the server-side.
If you are working with a client-side widget, it gets more complicated, as the indicator is part of the component caption, which is usually handled in the containing layout.
I just past all I have try, to found a solution, end goal is when is required is to have like this " Document Model * " and only * is in red
The problem is that I don't understand how you have created the component and for what your code is for. Is it from a connector of some widget? Which widget? What is the CustomComponent you mentioned?
Marko Grönroos: The problem is that I don't understand how you have created the component and for what your code is for. Is it from a connector of some widget? Which widget? What is the CustomComponent you mentioned?
The Server side Component extends CustomComponent
My main Component is a Panel
When user click on the Panel I open a layout that contain a TextBox to filter the list and a Lis of RadioButton or a List of Checkbox depending if is Multi Select or not
Hope this help you to understant better my component
I extend my Label by CustomField and is Done Thanks to All