Hello, thank you for this module and the evident effort being put into documenting and supporting it.
I'm defining a custom method very much like the one in clientside_validation.api.js.
In it, i'm trying to modify the message shown for a failed result. I've tried JQuery.extend:
jQuery.extend(jQuery.validator.messages, {
"ajaxFormMessage": result['message']
});
and also the jQuery.format addition to $(document).bind, but neither have any effect-- the default message defined in PHP, $js_rules[$element_name]['messages'][ajaxFormMessage]
is always used.
I've found the section that checks for $.metadata
in jquery.validate.js, which looks like it may be the key, but haven't figured out how to set it.
(Rationale for a message variable in the JavaScript-- using Clientside Validation to do serverside validation, such that the message may change based on the result of a MySQL query, for instance, "That title is already used by node/123".)
(Meta question-- ought i to be developing a major dependent module using the 7.x dev branch of the code?)
Comments
Comment #1
attiks CreditAttribution: attiks commentedThis sounds similar as what fapi_validation is doing, we added a new rule regexMatchPCRE inside http://drupalcode.org/project/clientside_validation.git/blob/refs/heads/... that basically does an ajax callback to check the values and it uses the return value for the message.
To add this to your module, you'll need to provide a new rule for the javascript that calls a callback function inside your module, you also have to implement clientside_validation_form_alter to add everything to the $js_rules array.
7.x-1.x (dev) is the version you need to develop against
Comment #2
attiks CreditAttribution: attiks commentedComment #3
mlncn CreditAttribution: mlncn commentedThe code pointed to, in its one setting of message.
is the same as i am using: http://drupalcode.org/project/formmsgs.git/blob/refs/heads/7.x-1.x:/form...
And the code pointed to is in clientside_validation.js, not in a clientside_validation_fapi.js file-- which leads me to believe the way it works might be hard-coded? I wish i could figure out where the ball is dropped and give more information but i haven't yet.
Comment #4
mlncn CreditAttribution: mlncn commentedTo be clear, i have all the callback stuff working fine-- it's overriding the default message that i cannot figure out how to do. Will try to follow what Clientside Validation FAPI does more closely.
Comment #5
mlncn CreditAttribution: mlncn commentedWow. My mistake, but wow hard to debug.
I was defining the default message in the rule like this:
Instead of, and then in addition to, like this:
I recall getting that alternate way ('messages' first) from looking at how it was actually done, i think right in jquery validate. So the problem here wasn't that this other way doesn't work, but that it works way too well-- that's what made the unshakable default message, that wouldn't stop until i deleted that first line.
Comment #6
mlncn CreditAttribution: mlncn commentedAnd... defining a default message with 'messages' at the end does not in fact work. But at least the messages changed on the fly work, which is more important to me. I'm thinking there is a bug here?
Comment #7
mlncn CreditAttribution: mlncn commentedComment #8
mlncn CreditAttribution: mlncn commentedAdding an array level to it [] also isn't working for me.
Comment #9
attiks CreditAttribution: attiks commentedThe right format is
An array isn't going to work, I guess your problem is that you want to be able to return more than 1 message for a certain element, which isn't possible; jquery.validate only allows one message for a certain rule/element combination.
Or am I missing your point? If so can you link some code so I can have a look.
Comment #10
attiks CreditAttribution: attiks commentedclosing, if you need more information feel free to re-open
Comment #11
MarcElbichon CreditAttribution: MarcElbichon commentedCan you explain what is the difference between
and
Comment #12
attiks CreditAttribution: attiks commentedIt should be
$js_rules[$name]['messages'][$method] = theme('clientside_error', $variables);
, so my comment in #9 is wrong, sorryComment #13
MarcElbichon CreditAttribution: MarcElbichon commentedI'm not sure because i've create a new rule with ajax like this :
and in hook_clientside_validation_rule_alter()
In my javascript, i call ajax and try to set error message by
This always print "ttttt" error message.
When i change to
Miracle, this is working !!!!
So, how must i do ?
Comment #14
MarcElbichon CreditAttribution: MarcElbichon commentedMy bad, if i only do
this is working too.
Does this mean that if $js_rules[$name]['messages']['toto'] is set, message never could be overriden ?