Supporting HTML on captions

Hello,

I don’t know if the Form objects actually support HTML code in their captions (the captions of the fields actually) or not, but my experience with them shows that this is not the case.

There’s something along the way that escapes strings like: “Hello
bla, bla, bla”, and I need captions to interpret that as HTML. I know one way would be to simple replace the caption manually with a Label, but I don’t want to lose additional caption properties, like left positioning and required marking.

I’ve taken a look at the current implementation of PaintTarget, namely JsonPaintTarget, but the answer doesn’t seem to be there, since this only escapes characters that could be misinterpreted as JSON.

So, in short, I would like to know if there’s currently a way to make a particular component such as an instance of Form support HTML content, without applying a custom caption structure, such as the aforementioned Label strategy or the CssLayout with a template strategy.

Thanks.

If you need HTML in form captions, I’d suggest using GridLayout as the form layout and overriding the attachField() in the Form so that it creates Label components in the caption column in HTML content mode, copies the caption from the fields and then sets the original captions to null. Well, you probably have several alternatives in how you do it, but that’s one way.

Can i add style or id to caption?

If you add a style name to a component, such as
addStyleName(“mystyle”),
the caption gets style
v-caption-mystyle
.

That’s at least in VerticalLayout and most other layouts, with components that don’t manage their own caption; the caption is usually managed by the layout, so the styling behaviour also depends on the layout.