blaze-forms icon indicating copy to clipboard operation
blaze-forms copied to clipboard

asynchronous validationValue

Open vanhumbeecka opened this issue 10 years ago • 1 comments

Question.

For example: what if you want to check username availability, can you make an asynchronous call to the server to check the availability inside the 'validationValue' element?

The code below doesn't work because Meteor.call is asynchronous. What is best practice here?

ReactiveForms.createElement({
    template: 'UserNameInput',
    validationEvent: 'keyup',
    validationValue: function(el, clean, template) {
        var v = $(el).val();
        console.log(v);
        Meteor.call('isUsernameAvailable', v, function(err, result) {
            if (err) {
                Meteor.Error('could not check username availability.');
            }
            return result;
        });
    }
});

vanhumbeecka avatar Oct 04 '15 15:10 vanhumbeecka

This example might help:

https://github.com/meteortemplates/forms/blob/release/2.0.0/docs/reference/examples/form-elements/advanced/FileUploader.md

Basically you have to return this.stop and then call this.validate(/* value */).

jonjamz avatar Oct 10 '15 03:10 jonjamz