Is there a way to auto capitilize the first letter of a field. I know we can use upper of lower case. But for example if a field contains firstname, if the user enters lloyd, is there a way to auto convert this to Lloyd?
I’ve been searching for a while now but didn’t find anything.
I suppose you want the name to be capitalized in the database. Then use the following approach with ValueChangeEvent:
public class PersonEdit extends StandardEditor<Person> {
@Inject
private InstanceContainer<Person> personDc;
@Subscribe("nameField")
public void onNameFieldValueChange(HasValue.ValueChangeEvent<String> event) {
if (event.isUserOriginated()) { // execute only if the change is done by user in UI component
String value = event.getValue();
if (value != null) {
// set capitalized value to the entity attribute
personDc.getItem().setName(StringUtils.capitalize(value));
}
}
}
}