Async Form Validation
Last modified by Vincent Massol on 2022/09/15
A new JavaScript API is available to help implement asynchronous form validation. It can be used like this:
require(['jquery', 'xwiki-form-validation-async'], function($) {
const titleInput = $('input[name=title]');
const validateTitle = () => {
if (!titleInput.val()) {
return Promise.reject();
} else {
return new Promise((resolve, reject) => {
...
});
}
};
titleInput.on('input', () => {
// Schedule the asynchronous validation after 500ms. The namespace is used to prevent replacing validations added by
// other modules.
titleInput.validateAsync(validateTitle, /* delay: */ 500, /* namespace: */ 'myModule');
});
});
const titleInput = $('input[name=title]');
const validateTitle = () => {
if (!titleInput.val()) {
return Promise.reject();
} else {
return new Promise((resolve, reject) => {
...
});
}
};
titleInput.on('input', () => {
// Schedule the asynchronous validation after 500ms. The namespace is used to prevent replacing validations added by
// other modules.
titleInput.validateAsync(validateTitle, /* delay: */ 500, /* namespace: */ 'myModule');
});
});