Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

Asynchronous validation

Tomáš Mlynarič edited this page May 7, 2017 · 2 revisions

Any validator may add asynchronous validation which may block UI thread. For this purpose, new methods were added to the api:

ValiFieldBase<ValueType> addCustomAsyncValidator(String errorMessage, AsyncPropertyValidator<ValueType> validator);

Also there was added checking progress of the validation, which may be used for informing user about the process.

@Bindable
boolean isInProgress() {
  return mInProgress;
}

Example:

addCustomAsyncValidator("This user already exists", new ValiFieldBase.AsyncPropertyValidator<String>() {
			@Override
			public boolean isValid(@Nullable String value) throws InterruptedException {
				Thread.sleep(2000);
				List<String> registeredUsernames = Arrays.asList("user", "name", "mlyko", "mlykotom", "charlie");
				return value != null && !registeredUsernames.contains(value.trim().toLowerCase());
			}
		});
Clone this wiki locally