New Features
- Added asynchronous validation functionality requested by @Swensson in #1 . The details on new feature can be read in README. A quick example:
defValidation('checkEmail', (value, { message }) => {
if (!value) return;
return apiClient.checkEmail(value)
.then((data) => {
if (!data.isValid) {
return Promise.reject(message || data.message || 'This email cannot be used');
}
})
});
function UserForm() {
const { $ } = useForm({
initial: { email: '', fullName: '' },
validations: {
rules: {
email: 'presence',
fullName: 'presence'
},
async: {
email: 'checkEmail'
}
}
});
}