Flow Binder field validator uniqueness

Hi,
I have the following question. I have an arraylist of Persons, each object has ID,Name etc…
I have a grid editor with a binder for i.e. the field name.
The user should not be able to add the same name that is contained in the arraylist (excluding itself, meaning if you are editing an object an error should not be shown)…

Has anyone created a UniqueValidator for the binder?
I now have the following:

ArrayList<Person> peopleData = new ArrayList<Person>();
Binder<Person> binder = new Binder<>(Person.class);
TextField nameField = new TextField();
....

binder.forField(nameField)
.withValidator(new StringLengthValidator("Cannot be empty or exceeding max characters" + " " + 21, 1,21))
.bind(Person::getName, Person::setName);

How could I add a validator that checks the peopleData list and validates that the “name” of the person is unique?
I could do it afterwards on Save, but I’m checking on how flexible validators are! :slight_smile:

You can create a custom Validator that checks the name for uniqueness.

.withValidator(v -> peopleData.stream().noneMatch(p -> p.getName().equals(v.getName())), "Name must be unique")

Ohhh I get it now!!
Excellent thanks!!!