views:

984

answers:

1

Hi!

I'm having an issue with a project I am working on at the moment that is making use of the Validation plugin for jQuery, when the validation error appears I am dynamically applying an anchor tag to it with an onclick. And its this onclick thats the problem...

The first time the validation error appears I have to click the link twice for the onclick event to be fired.

I have had a look at the page through the IE developer tool bar, and the anchor is wrapping the validation message correctly, with the onlick and all the necesary javascript files are attached

What goes on? Any suggestions would be greatfully appreciated :)

EDIT: added code snippets

jQuery(document).ready(function() {
     jQuery('#group-edit-form').validate({
   rules: {
    title: {
     required: true,
     remote: '<%=Url.Action("ValidateGroupName", new { id = ViewData["GroupId"] }) %>?parentId=' + getParentId()
    }
   },
   messages: {
    title: {
     required: getMessage (7002),
     remote: '<%= ((MessagingModel)ViewData["Messages"]).GetMessage (9001) %>'
    }
   }
  })

 });
 function getMessage(messageId) {
     var message = "<a id='errorMessageAnchor_" + messageId + "' onclick='messageBuilder(" + messageId + ")'><%= ((MessagingModel)ViewData["Messages"]).GetMessage (7002) %></a>";

     return message;
 }
+3  A: 

It's the blur event that is interfering with the anchor click.

You can choose one of this options:

  • Disable validation on blur event with onfocusout:false
  • Disable setting the focus on an invalid element with focusInvalid:false
Serhii
Used the focusInvalid:false option :) worked like a charm, thank you very much!
Wayne Austin