Skip to content

Add prioritization of configured error message over remote result. #547

Closed
wants to merge 8 commits into from

2 participants

@earino
earino commented Nov 12, 2012

There needs to be a way to say: "no matter what the remote call gives you, please use the error message that I provided, instead of the response from the back end." I do this by saying, if the error message configured starts with an exclamation mark (!), use it (after removing the exclamation mark), otherwise, feel free to use the response.

I am sorry I closed the previous pull request, I did not realize I could simply re-push my changes to it :-( I need to learn more about how github works.

Eduardo Arin... added some commits Nov 12, 2012
Eduardo Arino de la Rubia If the error message for a field starts with an !, use it (without th…
…e !) instead of the result

from the remote call.
ed6b96e
Eduardo Arino de la Rubia Actually works now, misunderstood how the match function worked in JS. c649716
Eduardo Arino de la Rubia Get rid of debugger call 6fa793c
@earino
earino commented Nov 12, 2012

Just verified that yes, indeed, re-pushing to my repo does update the pull request.

Eduardo Arino de la Rubia Added semicolon as per travis-ci aa303b9
@jzaefferer
Owner

Phantomjs timing out is probably not your fault, so we may ignore that. Still, your PR would need a unit test to be mergable.

Once that is in, you should also rebase your commits into a single one.

@earino
@earino
earino commented Nov 12, 2012

Ok, it builds and i added a unit test. I'm so very sorry this is such a mess :(

@jzaefferer
Owner

Thanks for the effort, we're getting there.

It loos like your editor changed a lot of whitespace in the test? The diff should have only your test, no other changes.

@earino
earino commented Nov 12, 2012

My effort < Your patience!

Yeah, looks like something wacky like that happened. Let me get that fixed, 'cause that's nonsense.

Eduardo Arin... added some commits Nov 12, 2012
Eduardo Arino de la Rubia Fixed spacing issues. 8693a0b
Eduardo Arino de la Rubia Fixed syntax error 1abbdb5
@earino
earino commented Nov 13, 2012

Ok, let me know if there is anything else you require!

@jzaefferer
Owner

I should've looked at the actual change earlier. What's your usecase that you need this API change? It sounds like you're dealing with a server response that you can't change on the server, but maybe you can just use the dataFilter option to clean up the response?

@earino
earino commented Nov 14, 2012

The use case is that there exists a class of messages for which our back end is giving horrible messages. Our front end people want a nice simple way of saying: "for this particular field, please just use the error message I provide, ignore what's coming from the server." Is that something that can be done easily with dataFilter?

@jzaefferer
Owner

So this works:

rules: {
    email: {
        remote: {
            url: "emails.php",
            dataFilter: function( response ) {
                if ( /err my gerd/.test( response ) ) {
                    return "\"better error message\"";
                }
                return response;
            }
        }
    }
}

Its a little clunky that you have to return a string escaped within a string, as the result is still parsed as JSON.

What do you think?

@jzaefferer jzaefferer referenced this pull request Feb 27, 2013
Closed

Meta: Documentation issues #656

0 of 2 tasks complete
@jzaefferer
Owner

The dataFilter approach seems okay for this special case. I've added added it to the list of things to document in #656.

@jzaefferer jzaefferer closed this Feb 27, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.