Inaccurate selector in jquery.validatethis.js?

7 views
Skip to first unread message

Jason Durham

unread,
May 26, 2013, 6:01:42 PM5/26/13
to valida...@googlegroups.com
https://github.com/bobsilverberg/ValidateThis/blob/49b3bdd28f525c87ddbade1572e81be9c1ae1f97/ValidateThis/client/jQuery/JS/jquery.validatethis.js

It seems like Line 109 should be trying to locate a condition for the form in which the element appears.  Instead, this selector finds the first form on the page.

Sample HTML:
===================================
<html>
<body>
<form>
....
</form>
<form id="edit-user">
<input name="username" />
<input name="currentUsername" type="hidden" />
</form>
</body>

Sample Client Rules:
===================================
{
  • conditions
    {
    • isNotCurrentUsername"$("input[name='username']").length > 0 && $("input[name='currentUsername']").getValue() !== $("input[name='username']").getValue()"
    },
  • messages
    {
      username: {
      • remote"Username already in use.",
      • required"The username is required."
      }
    },
  • rules
    {
    • emailAddress
      {
      • remote
        {
        • param
          {
          • url"/ColdboxProxy.cfc?method=isUniqueUsername&returnformat=plain"
          },
        • depends"isNotCurrentUsername"
        },
      • required
        {
        • DependentInputName"",
        • DependentInputValue"",
        • DependentInputDesc""
        }
      }
    }
}

Debugger output:
===================================
Uncaught TypeError: Cannot read property 'isNotCurrentUsername' of undefined


This is caused by line 109 of jquery.validatethis.js. The following is selecting the first form on the page (which has no ID, hence "... of undefined" in the error).

Current:
var formID = $(element).parents().find("form:first").attr("id");

Suggested Fix:
var formID = $(element).closest('form').attr("id");

Jason Durham

Reply all
Reply to author
Forward
0 new messages