How to programmatically show and hide the required indicator for a Custom field?

I have a custom field that does not contain any other fields inside it. And I need to programmatically show and remove the required indicator.
Before updating vaadin to version 24 I did it as follows:
@Override protected void setPresentationValue(List<ROW> newPresentationValue) { if (newPresentationValue.isEmpty()) { getElement().setProperty("value", ""); } else { getElement().setProperty("value", "some value"); } }
But after the update, this method doesn’t work as I get an errors:
Cannot read properties of undefined (reading 'parseValue')
Cannot read properties of undefined (reading 'c')

Did you try setRequiredIndicator(true/false)?

This looks like a workaround. Because in this case we manually manage the required attribute instead of having it set by binder based on external data. It also makes it difficult to handle situations where the required attribute changes dynamically.

From what I understand your workaround might change the state of the custom field (set it invalid).
To show and hide the required indicator, setRequiredIndicator(true/false) is the official way.

What are you trying to do? What was the previous version of Vaadin?

When a CustomField has an input a event is sent from the client side:

getElement().addEventListener("change", e -> this.updateValue());

You will have to trigger updateValue() manually if you don’t have an input.
In Vaadin 24, there are also a couple of changes/issues in the validation that might disturb you and should be changed in Vaadin 23.3.x (in alpha for now).