2011-04-06 55 views
0

我正在尝试benjamin的keens RSV validation脚本(jQuery版本),但是用自己的功能它不起作用。我的自定义函数返回false,但oncompletehandler仍然被称为?本杰明基恩rsv验证自己的功能不能正常工作?

$("#testForm").RSV({ 
    onCompleteHandler: myOnComplete, 
    displayType: "alert-one", 
    rules: [ 
     "required,first_name,Please enter your first name.", 
    "required,last_name,Please enter your last name.", 
    "required,email,Please enter your email address.", 
    "valid_email,email,Please enter a valid email address.", 
     "function,testfunct", 

    ] 
    }); 




function testFunc() { 
     tmpName = $('#tmpName').val(); 
     if (tmpName != '') { 
      //alert ("name has been set"); 
      return true; 
     } 
     else { 
      alert ("Credit card empt"); 
      $('#tmpName').focus(); 
      return false; 
      } 
    }` 

回答

1

您的自定义功能不正确。预计将返回:

  • 验证通过时为true。
  • 验证失败时,数组(但不是“false”)。

更多详情,请参考其official document,然后单击该项: “自定义的验证规则”

In order for your function to interact properly with the RSV script, your function must have a well-defined return value. Namely:

If the field passes whatever test or tests you administer, it must explicitly return true. If it fails the test(s), it has to return an array of arrays, like so:

return [[node1, "error message1"], [node2, "error message2"], [node3, "error message3"]]; 

Or if your function is just throwing a single error:

return [[node, "error message"]]; 

Note the double [[ and ]]. That's a not a typo!