I’m using Vaadin and have a set of textfields in a form. The textfields has focusListeners that triggers a method that focuses all the text in the texfield if there is any.
My problem though is that the auto selection works literally half the time. If I paste some text in a textfield, clicks outside the textfield and then clicks inside it the text will be selected. However, if I click outside again and then in the textfield the text will for a fraction of a second be selected to then only having the input marker where ever it was I clicked in the text.
Here’s the code:
class FormTextField extends FormLayout {
private static final long serialVersionUID = -2738069810605965508L;
String caption;
final STextField textField = Cf.formTextField(caption, "", 22);
public FormTextField(String textField) {
addStyleName("panelform");
setWidth(formWidth, UNITS_EM);
this.textField.setCaption(textField);
this.textField.setImmediate(true);
this.textField.addListener(new FieldEvents.FocusListener() {
@Override
public void focus(FocusEvent event) {
textFieldSelectAll();
}
});
addComponent(this.textField);
}
private void textFieldSelectAll() {
this.textField.selectAll();
}
public STextField getTextField() {
return textField;
}
}
}
I’m very interested to know if someone of you are familiar with this problem and have been able to sort it out?
If you want any more information from me then please ask!
I think you need to declare your FormTextField/STextField immediate too.
Hope this helps.