We use the validation plugin for jQuery extensively on our site. To make optimal use of the plugin, we wrote a bunch of custom validation methods. Some of these rules actually invoke a built-in validation method that came with the plugin. This is possible because the methods which are available to the plugin are kept in the $.validator.methods object. Suppose we have the following situation: we have a provider of trainings that requires interested people to enter their phone number when they want to receive more information about the training. Most providers do not require this, so validation of the phone number is dependent on this per-provider setting.
Simply doing the following won’t work, however:
If you run this, the browser will complain that
<Object> has no method 'depend'. This is because
this inside the
required method will now be the
methods object instead of the element being validated. Providing the correct value for the
this object is straightforward though, using the
Want to work at the biggest learning source in the world?