Programmatically set a TextField's value while in ReadOnly mode?

Basil Bourque :

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?

Elkfrawy :

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.

edited at
0

Comments

0 comments
Login to comment

Related

Programmatically set value in material-ui Autocomplete TextField

Flutter readonly Textfield set caret to end

Programmatically set a cell's value to the current date

How to set DropdownButton's value programmatically?

How to set value of RadGridView's column programmatically

Readonly Value not set in IE 11

Set value of textfield with javascript

Flutter set value to a textfield

react set value to a textfield

How to display some editor functions in Richface's editor while the readonly attribute is set to true?

Set Child Component TextField's Value to Parent Components Dropdown Selection?

In JavaFX, Is it possible to enable a CheckBox when the TextField's value is not set to Zero

Set timepicker value programmatically

Set value button programmatically

Trying to programmatically set value of a list item's URL column

Making all form inputs to be in readonly mode while clicking submit button

Set readonly property value through reflection

SwiftUI Textfield - How to set the background Color for textfield in edit mode to clear

useEffect to set value of TextField not working

use uidatepicker to set textfield value

Can I set the value of a TextField in one scene from another scene, while both scenes are showing?

How to set value programmatically on 4.0.2

programmatically set Paypal purchase 'value'

Set the Modulation Wheel Value programmatically

failing to set value while using provider's constructor in flutter

set global variable's value in a function while check in another in python

Run program in readonly mode

How to set value to second page textfield from Main page textfield

Set flutter textfield inside Listview and get the value of each textfield on submit