Ok, that makes it a bit more difficult. For a workaround, try
something like this:

$.validator.addMethod("customRemote", function(value, element) {
  if (!remoteRequired(element) {
    return "dependency-mismatch";
  }
  return $.validator.methods.remote.apply(this, arguments);
}, $.validator.messages.remote);

The idea is to write a custom method that does the dependency-check.
If it isn't necessary, return a special string to have the plugin skip
the method. Otherwise, delegate to the default remote method to
perform its task.

Let me know if that works for you, might be worthwhile adding to the
docs (until depends/remote is fixed).

Jörn

On Fri, Apr 17, 2009 at 3:34 PM, snobo <g...@riga.ahlers.com> wrote:
>
> well, I don't see how required can help me... what I want is to make a
> remote call/check ONLY under certain circumstances. Plus, this field
> is "constantly"-required already anyway...
>
> actually, now I think there might be various workarounds, e.g.
> creating a custom method, which would check the condition first and
> then making an AJAX call manually only if needed...
>
> On Apr 17, 4:16 pm, Jörn Zaefferer <joern.zaeffe...@googlemail.com>
> wrote:
>> This is indeed a bug, in this case something never tested for.
>>
>> Is using required: function() {} together with remote an option?
>>
>> Jörn
>>
>> On Fri, Apr 17, 2009 at 3:03 PM, snobo <g...@riga.ahlers.com> wrote:
>>
>> > I've been trying to use remote method coupled with depends, like this:
>>
>> > remote: {
>> >        depends: function(element) { element.value = $.trim(element.value);
>> > return element.defaultValue != element.value; },
>> >        url: 'my.php',
>> >        type: 'post',
>> >        data: { action: 'check_user_name' }
>> > }
>>
>> > and this doesn't work, because the whole remote parameter array gets
>> > overwritten with the result of evaluating my 'depends' function (so
>> > instead of array it becomes a scalar, true or false). Therefore in
>> > case of false the AJAX call doesn't happen, and in case of true an
>> > error occurs (because there's no url, no type, and no data anymore).
>>
>> > I assume remote and depends are incompatible, is it correct? If yes,
>> > is there a workaround for this?
>>
>> > TIA
>> > cheers

Reply via email to