ysny.karibu-tools.karibu-tools.0.20.source-code.Validators.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of karibu-tools Show documentation
Show all versions of karibu-tools Show documentation
Karibu-Tools: The Vaadin Missing Utilities
package com.github.mvysny.kaributools
import com.vaadin.flow.data.binder.Validator
import com.vaadin.flow.data.binder.ValueContext
import com.vaadin.flow.data.validator.RangeValidator
/**
* Checks whether the validator passes or fails given [value].
*/
public fun Validator.isValid(value: T?): Boolean = !apply(value, ValueContext()).isError
/**
* Workaround for Kotlin requiring non-null values for [RangeValidator.of].
* Requires that the value is in the range `min..max`, including.
*/
public fun > rangeValidatorOf(errorMessage: String, min: T?, max: T?): RangeValidator =
RangeValidator(errorMessage, Comparator.nullsFirst(Comparator.naturalOrder()), min, max)