Skip to content

UITextArea :: changing the text programmatically does not work consistently #542

@fls-indinf

Description

@fls-indinf

Hi JVx-Engineering Team!

On the following workscreen:

Image
public class SimpleWorkScreen extends DataSourceWorkScreen {

  public SimpleWorkScreen(IWorkScreenApplication pApplication, AbstractConnection pConnection) throws Throwable {
    super(pApplication, pConnection, null);

    setLayout(new UIFlowLayout());

    var area = new UITextArea("init text");
    add(area);

    var button = new UIButton("setText", () -> area.setText("something else"));
    add(button);
  }
}

When pressing the setText -Button, the text in the textarea will not update, even tho the response of the pressButton does contain it correctly:

[
    {
        "componentId": "WS1",
        "changedComponents": [
            {
                "id": "TA159",
                "text": "something else"
            }
        ],
        "name": "screen.generic",
        "update": true,
        "home": false
    }
]

As our team analyzed it, the problem seems to be the 'copying' of just the initial state.

/** Current state of the textarea value */    
const [text, setText] = useState(props.text || ""); 

For cross-checking, adding a hook to react to changes of the properties seems to do the trick.

useEffect(() => {        
  setText(props.text ?? "");    
}, [props.text]); 

Is this a viable solution for this?

Thank you for your support.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions