With JQuery Validation Plugin, I want to change the remote validation method

前端 未结 3 1344
醉酒成梦
醉酒成梦 2020-12-19 20:18

I\'m using jquery validate plugin to validate an email address against a database using the remote method of this plugin.

I need to check the email address is not i

相关标签:
3条回答
  • 2020-12-19 20:53

    From what I can tell, this may be a limitation of the validate plugin. There are several options for triggering the validation (which is what you want to do) given at http://docs.jquery.com/Plugins/Validation/validate#toptions but I don't see a way to trigger validation on one element when another element changes.

    Your best bet is to place your validation code in something like this:

    $('select#siteid').onChange(function(){
            $('form.validatedform').validate({ 
                     rules:{
                           email: {
                                  required: true,
                                  email: true,
                                  remote: 'emailcheck2.asp?siteid=' + $('#siteid').val()
                           }
                      }
             });
      });
    
    0 讨论(0)
  • 2020-12-19 20:54

    The plugin caches the value for performance reasons. As a workaround for now you could try to invalidate the cache manually whenever the dependent value changes:

    $("#site").change(function() {
      $("#email").removeData("previousValue");
    });
    0 讨论(0)
  • 2020-12-19 21:04

    Hi if you are using this jquery valdation plugin, http://docs.jquery.com/Plugins/Validation/validate

    If you want to send additional parameters(e.g. siteid) for remote validation, you can do something like this:

    var enquiryform = {
            rules: {
                email: {
                    required: true,
                    email: true,
                    remote: {
                        url: "emailcheck2.asp", //this should be the full path url including base url
                        data: {
                            siteid: function() {
                                return $('#siteid').val();
                            }
                        }
                    }
                }
            }
        };
    
    0 讨论(0)
提交回复
热议问题