Hi,
How can I make all text in TextField component selected when it get focus or user enter into it?
Hi,
How can I make all text in TextField component selected when it get focus or user enter into it?
Hi @haattila
To add new functionality, you need to extend the TextField
component. Follow these steps:
CubaTextFieldWidget
. Create CustomTextFieldWidget
class in web.toolkit.ui.client.customtextfield package:package com.company.sample.web.toolkit.ui.client.customtextfield;
import com.google.gwt.event.dom.client.FocusEvent;
import com.haulmont.cuba.web.widgets.client.textfield.CubaTextFieldWidget;
public class CustomTextFieldWidget extends CubaTextFieldWidget {
@Override
public void onFocus(FocusEvent event) {
super.onFocus(event);
selectAll();
}
}
CubaTextFieldWidget
with CustomTextFieldWidget
in AppWidgetSet.gwt.xml<?xml version="1.0" encoding="UTF-8"?>
<module>
<inherits name="com.haulmont.cuba.web.widgets.WidgetSet"/>
<replace-with class="com.company.sample.web.toolkit.ui.client.customtextfield.CustomTextFieldWidget" >
<when-type-is class="com.haulmont.cuba.web.widgets.client.textfield.CubaTextFieldWidget"/>
</replace-with>
</module>
I also attached the test project textfield-select-all.zip (76.4 KB).
Regards,
Gleb