Skip to content
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

Async rules fail and show "success" even if they get 200 OK from the api #24

Open
vlascik opened this issue Nov 26, 2015 · 11 comments
Open

Comments

@vlascik
Copy link

vlascik commented Nov 26, 2015

Async rules fail and show "success" even if they get 200 OK from the api

image

        Dominar.Validator.registerAsync('username_taken', function (username, attribute, parameters, passes) {
            $.get(url, {username: username}, passes)
                .fail(function (response) {
                    passes(false, response.responseJSON.message);
                });
        });
@garygreen
Copy link
Owner

Dominar doesn't check what response from the server is at all, it's down to the user to call passes()

Dominar.Validator.registerAsync('username_taken', function (username, attribute, parameters, passes) {
    $.get(url, { username: username }, passes)
        .done(function() {
            passes();
        })
        .fail(function (response) {
            passes(false, response.responseJSON.message);
        });
    });
});

Also atm dominar doesn't support having a 'success message' only a failed message. I can add support for that though, would be pretty useful.

@vlascik
Copy link
Author

vlascik commented Nov 26, 2015

It would be useful I guess, but at the moment I'm trying to make the validation pass (make input box green and hide the "success" message), even after I added a call to passes() in .done(), the result is the same as on picture.
Edit: For some reason it seems, that the async validation rule is both in passed and failed, so AsyncResolvers.isAllResolved() returns false, as (this.passed.length + this.failed.length) is higher than this.resolversCount;

@garygreen
Copy link
Owner

Can you setup a fiddle or repo I can check?
On 26 Nov 2015 19:41, "vlascik" notifications@github.com wrote:

It would be useful I guess, but at the moment I'm trying to make the
validation pass (make input box green and hide the "success" message), even
after I added a call to passes() in .done(), the result is the same as on
picture.


Reply to this email directly or view it on GitHub
#24 (comment).

@vlascik
Copy link
Author

vlascik commented Nov 26, 2015

I edited the comment above with more info, did it help by any chance?
But the code is the same as in your example, passes() is called. Maybe the previous failure of the same rule isn't removed?

@garygreen
Copy link
Owner

What does your dominar initialisation look like?
On 26 Nov 2015 20:00, "Gary Hole" holegary@gmail.com wrote:

Can you setup a fiddle or repo I can check?
On 26 Nov 2015 19:41, "vlascik" notifications@github.com wrote:

It would be useful I guess, but at the moment I'm trying to make the
validation pass (make input box green and hide the "success" message), even
after I added a call to passes() in .done(), the result is the same as
on picture.


Reply to this email directly or view it on GitHub
#24 (comment).

@vlascik
Copy link
Author

vlascik commented Nov 26, 2015

var validator = new Dominar(document.getElementById('the-form'), {
    username: {
        rules: 'required|email|username_taken',
        triggers: ['keyup', 'change', 'focusout'],
        delay: 300
    }
}));

@garygreen
Copy link
Owner

I can't seem to replicate the issue, seems to work fine for me. http://jsfiddle.net/18yb3aja/

@vlascik
Copy link
Author

vlascik commented Nov 26, 2015

I've setup a fiddle which shows the problem here: http://jsfiddle.net/dnran7da/4/
I had to upload own dominar-standalone.js that i had to manually npm build from yesterday's master (before your latest commits), as the one in dist/ is not updated, maybe that could be the issue?

@garygreen
Copy link
Owner

If you put passes as the third parameter to .get you need to make sure you don't return 200 for the .fail to be called when validation should fail.

@vlascik
Copy link
Author

vlascik commented Nov 26, 2015

Yep, that was it, it works now, also a call to .done(function() { passes()
is not mentioned there.
Thanks.

@vlascik vlascik closed this as completed Nov 26, 2015
@vlascik
Copy link
Author

vlascik commented Nov 26, 2015

Also, it should say:

              .done(function() {
                    passes();
              }).
                .fail(function (response) {
                    passes(false, response.responseJSON.message);
                });

to show response message, response.message will be undefined

@vlascik vlascik reopened this Nov 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants