summaryrefslogtreecommitdiffstats
path: root/server/src/main
diff options
context:
space:
mode:
authorMárcio P. Dantas <marciopd@gmail.com>2018-03-26 17:44:28 +0300
committerIlia Motornyi <elmot@vaadin.com>2018-03-26 17:44:28 +0300
commit3c52491a5b44456f94777e6cec71af2a1a70ae46 (patch)
treefd9853a6a92265d99378fd1707c905a933345772 /server/src/main
parentf3e06f4f4157ed4675619608b5da4cd7e5584876 (diff)
downloadvaadin-framework-3c52491a5b44456f94777e6cec71af2a1a70ae46.tar.gz
vaadin-framework-3c52491a5b44456f94777e6cec71af2a1a70ae46.zip
Added method asRequired with a custom required validator to BindingBuilder. (#10724)
Diffstat (limited to 'server/src/main')
-rw-r--r--server/src/main/java/com/vaadin/data/Binder.java30
1 files changed, 27 insertions, 3 deletions
diff --git a/server/src/main/java/com/vaadin/data/Binder.java b/server/src/main/java/com/vaadin/data/Binder.java
index f9e076e13f..360daa73bf 100644
--- a/server/src/main/java/com/vaadin/data/Binder.java
+++ b/server/src/main/java/com/vaadin/data/Binder.java
@@ -728,6 +728,23 @@ public class Binder<BEAN> implements Serializable {
*/
public BindingBuilder<BEAN, TARGET> asRequired(
ErrorMessageProvider errorMessageProvider);
+
+ /**
+ * Sets the field to be required and delegates the required check to a custom validator.
+ * This means two things:
+ * <ol>
+ * <li>the required indicator will be displayed for this field</li>
+ * <li>the field value is validated by customRequiredValidator</li>
+ * </ol>
+ *
+ * @see HasValue#setRequiredIndicatorVisible(boolean)
+ * @param customRequiredValidator
+ * validator responsible for the required check
+ * @return this binding, for chaining
+ * @since
+ */
+ public BindingBuilder<BEAN, TARGET> asRequired(
+ Validator<TARGET> customRequiredValidator);
}
/**
@@ -885,11 +902,18 @@ public class Binder<BEAN> implements Serializable {
@Override
public BindingBuilder<BEAN, TARGET> asRequired(
ErrorMessageProvider errorMessageProvider) {
+ return asRequired(
+ Validator.from(
+ value -> !Objects.equals(value, field.getEmptyValue()),
+ errorMessageProvider));
+ }
+
+ @Override
+ public BindingBuilder<BEAN, TARGET> asRequired(
+ Validator<TARGET> customRequiredValidator) {
checkUnbound();
field.setRequiredIndicatorVisible(true);
- return withValidator(
- value -> !Objects.equals(value, field.getEmptyValue()),
- errorMessageProvider);
+ return withValidator(customRequiredValidator);
}
/**