Skip to content

Async validators #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jmverges opened this issue Mar 28, 2017 · 14 comments
Closed

Async validators #170

jmverges opened this issue Mar 28, 2017 · 14 comments

Comments

@jmverges
Copy link
Contributor

jmverges commented Mar 28, 2017

Hi folks,

I'm trying to do this:

Vue.use(VueFormGenerator);
    VueFormGenerator.validators.short = function (value, field) {
        if (value.length < 3) {
            return ['The short must have at least 3 characters'];
        }

        return axios.post('api/scaffolder/validate-short', {"short": value}).then(response => {
                    if (response.data.valid == false) {
                        return ['The short already exists'];
                    }
                    return null;

                });
    };

However if the value is > 2 field is always in green, even if response.data.valid is false. Is VFG able to have ajax validations?

Best,
Juan Manuel.

@cristijora
Copy link
Collaborator

Can you post the usage of your validator ?

This part seems a bit wrong to me since your are returning a Promise here basically instead of an array

return axios.post('api/scaffolder/validate-short', {"short": value}).then(response => {
                    if (response.data.valid == false) {
                        return ['The short already exists'];
                    }
                    return null;

                });

@icebob
Copy link
Member

icebob commented Mar 28, 2017

vfg can't support async validators.

@jmverges
Copy link
Contributor Author

@icebob really?

@jmverges
Copy link
Contributor Author

@icebob but would you like to support them? if not I couldn't use this repo anymore

@jmverges
Copy link
Contributor Author

what about drop de built in validation, change the fields generation and integrate with Vee Validate?

@cristijora
Copy link
Collaborator

Dont think that's an option. For example I got rid of Vee validate and all it's stuff and switched to form generator and form generator validations because Vee validate requires a lot of boilerplate code. If you want a field validation you have to add like 3 html wrappers and functions and it gets really messy with custom components like date pickers or external stuff you cannot control so easily.

@jmverges
Copy link
Contributor Author

yep, that's why I bet for VFG when I saw it, however, ajax validation is a must for me as is the most common use case in my world. Not having this feature implemented here makes the library less powerful (no offence). I could spend a bunch of hours working on this feature if @icebob wants to support async validation and he has an idea about which path to take for this one.

@cristijora
Copy link
Collaborator

Does vee validate support async validation?

@jmverges
Copy link
Contributor Author

@cristijora yes, it works quite well.

@cristijora
Copy link
Collaborator

Can you post a fiddle so I understand how it works?

@icebob icebob changed the title Validator with ajax Async validators Mar 28, 2017
@icebob
Copy link
Member

icebob commented Mar 28, 2017

@jmverges I think it is a good feature.

@icebob
Copy link
Member

icebob commented Mar 28, 2017

I'm trying a quick implementation with Promise

@cristijora
Copy link
Collaborator

Please share the result/attempt in a PR maybe.

@icebob
Copy link
Member

icebob commented Mar 28, 2017

@jmverges I implemented. If you can, please try it.

@icebob icebob closed this as completed Mar 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants