Coyote Forms is a cross-field input validator. It lets you create complex rule sets using simple expressions and a couple of bindings.
Rules can be defined using similar syntax to:
{
{
"inputIds": ["city"],
"condition": [
"region is EMEA",
"country is United Kingdom"
],
"permittedValues": [ "London" ]
},
}
Which reads as if region is EMEA and country is United Kingdom then city can be London
.
Integration takes place by creating bindings between your pojo and the validator:
public class LocationDtoConnector implements Connector<LocationDto> {
@Override
public Map<String, String> collectInputValues(LocationDto obj) {
return Map.of(
"region", obj.getRegion() == null ? "" : obj.getRegion(),
"country", obj.getCountry() == null ? "" : obj.getCountry(),
"city", obj.getCity() == null ? "" : obj.getCity()
);
}
}
The validator can be instantiated with a rule set and a connector. After instantiation the following methods will be available:
public List<String> queryValidValues(String inputId, T inputValues)
For retrieving the possible values of a discrete value set input. And
public List<ValidationFailure> validate(T inputValues)
For validating a set of inputs.
The project ships with three example projects located in the examples folder. See details in the Examples readme.
First, I would like to publish the 0.1 Release. After that, the most beneficial next step would be to implement the validator in javascript, and therefore make it possible to perform validation on the frontend using the same ruleset. Faster response times, less load and less code duplication would be the benefit. After that, we will see.