I’m currently setting a TextField to read-only using JavaScript and triggering it manually in InitEvent.
@Subscribe
public void onInit(InitEvent event) {
textField.addStyleName("readonly-input");
Page page = UI.getCurrent().getPage();
page.getJavaScript().execute("$('.readonly-input').prop('readonly', true)");
}
But when I switch to another tab get back to current tab, the browser removes the read-only attribute of the TextField. I tried to re-run the code above but I don’t know which event will be triggered when switching tab.
How can I prevent the read-only attribute to be removed or re-run the code above? Which event will be fired when switching tab? Please help.
NOTE: I don’t want to use the editable = false or enable = false property because it will change the UI of the TextField.