|
25 | 25 | import java.util.stream.Collectors; |
26 | 26 | import java.util.stream.Stream; |
27 | 27 |
|
| 28 | +import com.vaadin.experimental.Feature; |
| 29 | +import com.vaadin.experimental.FeatureFlags; |
28 | 30 | import com.vaadin.flow.component.*; |
29 | 31 | import com.vaadin.flow.component.datepicker.DatePicker.DatePickerI18n; |
30 | 32 | import com.vaadin.flow.component.dependency.JsModule; |
|
35 | 37 | import com.vaadin.flow.data.binder.ValidationResult; |
36 | 38 | import com.vaadin.flow.data.binder.Validator; |
37 | 39 | import com.vaadin.flow.function.SerializableFunction; |
| 40 | +import com.vaadin.flow.server.VaadinService; |
38 | 41 |
|
39 | 42 | @Tag("vaadin-date-time-picker-date-picker") |
40 | 43 | @NpmPackage(value = "@vaadin/polymer-legacy-adapter", version = "23.2.0-beta2") |
@@ -624,7 +627,11 @@ public boolean isInvalid() { |
624 | 627 |
|
625 | 628 | @Override |
626 | 629 | public Validator<LocalDateTime> getDefaultValidator() { |
627 | | - return (value, context) -> checkValidity(value); |
| 630 | + if (isFeatureFlagEnabled(FeatureFlags.ENFORCE_FIELD_VALIDATION)) { |
| 631 | + return (value, context) -> checkValidity(value); |
| 632 | + } |
| 633 | + |
| 634 | + return Validator.alwaysPass(); |
628 | 635 | } |
629 | 636 |
|
630 | 637 | private ValidationResult checkValidity(LocalDateTime value) { |
@@ -804,4 +811,25 @@ public void removeThemeVariants(DateTimePickerVariant... variants) { |
804 | 811 | Stream.of(variants).map(DateTimePickerVariant::getVariantName) |
805 | 812 | .collect(Collectors.toList())); |
806 | 813 | } |
| 814 | + |
| 815 | + /** |
| 816 | + * Returns true if the given feature flag is enabled, false otherwise. |
| 817 | + * <p> |
| 818 | + * Exposed with protected visibility to support mocking |
| 819 | + * <p> |
| 820 | + * The method requires the {@code VaadinService} instance to obtain the |
| 821 | + * available feature flags, otherwise, the feature is considered disabled. |
| 822 | + * |
| 823 | + * @param feature |
| 824 | + * the feature flag. |
| 825 | + * @return whether the feature flag is enabled. |
| 826 | + */ |
| 827 | + protected boolean isFeatureFlagEnabled(Feature feature) { |
| 828 | + VaadinService service = VaadinService.getCurrent(); |
| 829 | + if (service == null) { |
| 830 | + return false; |
| 831 | + } |
| 832 | + |
| 833 | + return FeatureFlags.get(service.getContext()).isEnabled(feature); |
| 834 | + } |
807 | 835 | } |
0 commit comments