1

Re: Note on using jQuery Validation and OpenLayers together on IE

If you happen to use the mnhnl dynamic 1 form in the IForm Drupal module you may notice that one of the user interface options is to enable client-side validation. That would, for example, check that numeric fields only have numbers in before trying to submit to the warehouse. It makes for a more helpful and responsive user interface. However, there is a little note beside the option saying "there are bugs in Internet Explorer which can cause errors when clicking on the map if this box is ticked"

What this means is that, assuming you want to support the world's most used (and my least liked) browser then you have to make a choice between having a map for inputting location information or client-side validation. This was bad news for me recently as really needed both so I investigated.

What I found is that validation is done by the jQuery Validation plugin. This attaches a click handler to the form so that when you click on anything in the form, including the map, the module checks it to see whether it needs to validate something. jQuery is called to answer the question, "what type of thing just got clicked" and when that thing happens to be certain map-related items IE does not play nicely with jQuery. This may now be fixed in more recent versions of jQuery but we are using 1.3.2 because that is what Drupal 6 is compatible with.

I came up with a workaround to this problem but not a way to integrate my fix into the Indicia code in a generic way, hence I am documenting it here. My workaround was to skip validation if the click fell within the map. I edited my local copy of iform/media/js/jquery.validate.js and modified the event handler which is right at the end of the file

Where the original event handler reads

if (target.is(delegate)) {
  return handler.apply(target, arguments);
}

I modified it to

if (target.parents('#map').length == 0) {
  if (target.is(delegate)) {
    return handler.apply(target, arguments);
  }
}

Target is the thing that has been clicked and 'map' is the id of the <div> that contains my map so my conditional statement is saying 'if the thing clicked is not in the map div then go ahead and try to validate it'

Any improvements to this very welcome.

Jim Bacon.

2

Re: Note on using jQuery Validation and OpenLayers together on IE

Hi Jim
Interested to know why you think this fix is not an improvement generically, that can be integrated into the code?

John van Breda
Biodiverse IT

3

Re: Note on using jQuery Validation and OpenLayers together on IE

Hi John

I didn't like my fix for two reasons:

1. The modification is in the jQuery.Validate module which might well be improved by its developers and which we might well want to upgrade in the future. It would be very easy to loose any modifications we have made in the process so it is a bad place in the code to try to make a fix.

2. Also, I have hard-coded the id of the map container div and there is no certainty that another user would have the same id.

I have since had another idea which is to add an event handler in our javascript and attach it to the map div. If we emit the script from PHP we will know the id of the map div. The purpose of the handler would be to cancel the bubbling of the event up the DOM as the validate event  is attached to the form, which is higer in the DOM. I haven't had a chance to try this out though.

Jim.

4

Re: Note on using jQuery Validation and OpenLayers together on IE

Hi Don,

The problem that I experienced with IE occurred when I had selected a grid square on my map and then clicked again within that grid square. The target of the click is the square and this is what IE fails to find the attributes of. Lots of error messages arise.

I did investigate the 'ignore' option but it is no help as the fault arises in almost the very first line of the code that the validate module executes when it is deciding whether to do anything at all - long before the test of whether to then ignore it.

Jim

5

Re: Note on using jQuery Validation and OpenLayers together on IE

Hi

I've committed a change (in branch 0.8.1 and trunk) to jquery.indiciaMapPanel.js which implements the alternative idea I had of intercepting the map click events as they bubble up the DOM. It appears to be effective in the rather limited testing that I have performed.

By patching the code here we  have full control over it, it works regardless of the name given to the map div, and it will fix map panels wherever they are used.

Hope this works. Thanks for the discussion.

Jim.