Vaadin widgets offer setEnabled
and setReadOnly
methods. I want the visual black color readability of the read-only state rather than greyed-out disabled state. My goal is to prevent the user from making direct data entry.
Unfortunately, the read-only mode on a TextField not only prevents the user from data entry. It also prevents me from programmatically setting the value with a call to setValue
.
The workaround is to have my code (1) Call setReadOnly with False, (2) Call setValue, (3) call setReadOnly with True.
➤ Is there a simpler way to change the value of a TextField while in read-only mode?
I don't think there is a simpler way to change value of a TextField
in read-only mode, if you go through the source code for AbstractField
setValue
method, you can discover that.
But you still can do that on your own using simple function like:
public void setValue(TextField textField, String value) {
if (textField.isReadOnly()) {
textField.setReadOnly(false);
textField.setValue(value);
textField.setReadOnly(true);
} else {
textField.setValue(value);
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments