Using Cuba 6.9.1
lane_id has an integer as an Entity attribute type
Problem:
• User can enter string but we want to validate that only integer input is allowed. I need to change message in the bottom corner to different message instead of “Alert Input Error”
• Textfield addValueChangeListener doesn’t work but addTextChangeListener does work. but we want user to enter the whole string and then click on different field
• Cannot find what method or approach to detect out of focus for textField or FieldGroup
when I enter letters nothing happens.
As soon as I leave the input box, the input error appears in the bottom right corner and the text got erased
Attempt 1: Doesn’t solve exactly what I need but at least it shows different message every time user enters letter. I still want to use the “Alert Input Error” message box with different message like “Must be integer”
LanesEdit.xml
lanesEdit.java
public class LanesEdit extends AbstractEditor<Lanes> {
@Named("fieldGroup.laneID")
protected TextField laneID;
@Override
public void init(Map<String, Object> params) {
laneID.addTextChangeListener( event -> {
String laneIDInput = event.getText();
System.out.println(laneIDInput);
if (!NumberUtils.isNumber(laneIDInput)) {
throw new ValidationException(getMessage("Must be integer "));
}
});
}
}
result:
Attempt 2: to detect datasource item change. However this method obtains the value only after user clicks ok button. This does not work as well.
Attempt 3: called all the methods in AbstractEditor. None of those methods can detect textfield out of focus
Textfield addValueChangeListener doesn’t work
Other good solution is to turn off the validation on the lane_id textfield and use postValidate method when user clicks okay. This allows me to have different message in the Alert box. However, I could not find how to turn it off.
Can someone have any idea how to solve or approach this issue?