You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I populate my form in afterNavigation, which should be the most common scenario, i.e. usually loading data from backend is premature in the constructor or beforeEnter. If in my application it is possible that backend has invalid data, which needs to be corrected, I want to call binder.validate() after readBean. This kind of backfilling process is rather common.
Now for some reason DatePicker and IntegerField are still shown valid, although the date is in the past.
There is a workaround to delay validate call to the next client roundtrip
@Override
public void afterNavigation(AfterNavigationEvent event) {
var pojo = new Pojo();
pojo.setDate(LocalDate.of(1971, 12, 10));
binder.readBean(pojo);
getElement().executeJs("return 0;").then(res -> {
binder.validate();
});
}
Expected behavior
The fields are shown invalid.
Minimal reproducible example
Use the view below to replicate the issue:
@Route(value = "datepicker", layout = MainLayout.class)
public class DatePickerView extends VerticalLayout
implements AfterNavigationObserver {
private Binder<Pojo> binder;
public DatePickerView() {
setMargin(true);
setSpacing(true);
setSizeFull();
var datePicker = new DatePicker();
var integerField = new IntegerField();
binder = new Binder<>();
binder.forField(datePicker)
.withValidator(value -> value.isAfter(LocalDate.now()),
"No future")
.bind(Pojo::getDate, Pojo::setDate);
binder.forField(integerField)
.withValidator(value -> value >= 0, "No positive")
.bind(Pojo::getNumber, Pojo::setNumber);
add(datePicker, integerField);
}
@Override
public void afterNavigation(AfterNavigationEvent event) {
var pojo = new Pojo();
pojo.setDate(LocalDate.of(1971, 12, 10));
pojo.setNumber(-10);
binder.readBean(pojo);
binder.validate();
}
public class Pojo {
private LocalDate date;
private Integer number;
public LocalDate getDate() {
return date;
}
public void setDate(LocalDate date) {
this.date = date;
}
public Integer getNumber() {
return number;
}
public void setNumber(Integer number) {
this.number = number;
}
}
}
Versions
Vaadin / Flow version: 24.6.5
The text was updated successfully, but these errors were encountered:
Description of the bug
When I populate my form in
afterNavigation
, which should be the most common scenario, i.e. usually loading data from backend is premature in the constructor orbeforeEnter
. If in my application it is possible that backend has invalid data, which needs to be corrected, I want to callbinder.validate()
afterreadBean
. This kind of backfilling process is rather common.Now for some reason
DatePicker
andIntegerField
are still shown valid, although the date is in the past.There is a workaround to delay validate call to the next client roundtrip
Expected behavior
The fields are shown invalid.
Minimal reproducible example
Use the view below to replicate the issue:
Versions
The text was updated successfully, but these errors were encountered: