You've got the this.optional(element) stuff included, so that method works just like the builtin methods, unless something else is broken.
Jörn On Thu, Aug 6, 2009 at 10:37 PM, Jim Evans<ximxim...@googlemail.com> wrote: > > Hi, > > I'm using the validator plugin and it's great! I understand the > following: > > "Before a field is marked as invalid, the validation is lazy: Before > submitting the form for the first time, the user can tab through > fields without getting annoying messages - he won't get bugged before > he had the chance to actually enter a correct value" > > This is cool and how I want it to work. > > However, I have some custom validation methods using addMethod like: > > $.validator.addMethod("currency", function(value, element){ > element.value = $.trim(value); > return this.optional(element) || /^([0-9]+|[0-9]{1,3}(,[0-9]{3})*)(\. > [0-9]{2})?$/.test(element.value); > }, 'This value should be in the form 1234, 1234.56 or 1,234.56'); > > These custom methods validate eagerly from the start, i.e. before I've > tried to submit the form. This means that in a form with one input > using say this 'currency' method, and another input using the built in > 'required' method, as I tab through them, the required one will not be > validated but the currency one will. > > How can I ensure that these custom validation methods only validate > after initial submit/validation has occurred, like the built in ones > do? > > Many thanks, > > Jim. >