All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ysny.karibu-tools.karibu-tools.0.20.source-code.Validators.kt Maven / Gradle / Ivy

There is a newer version: 0.21
Show newest version
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)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy