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

io.imunity.vaadin.elements.NoSpaceValidator Maven / Gradle / Ivy

/*
 * Copyright (c) 2021 Bixbit - Krzysztof Benedyczak. All rights reserved.
 * See LICENCE.txt file for licensing information.
 */

package io.imunity.vaadin.elements;

import com.vaadin.flow.data.binder.ValidationResult;
import com.vaadin.flow.data.binder.Validator;
import com.vaadin.flow.data.binder.ValueContext;

import java.util.function.Function;

public class NoSpaceValidator implements Validator
{

	private final Function msg;

	public NoSpaceValidator(Function msg)
	{
		this.msg = msg;
	}


	@Override
	public ValidationResult apply(String value, ValueContext context)
	{
		if (value != null && value.contains(" "))
		{
			return ValidationResult.error(msg.apply("NoSpaceValidator.noSpace"));
		}

		return ValidationResult.ok();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy