A content type that includes a field type of OpenLayers WKT (and an OpenLayers map widget) has content generated for it even when the map widget has no content, i.e. when saving the node the WKT field is automatically populated with the text "GEOMETRYCOLLECTION()" when the map is empty.

This seems to result in the field passing the "required field" criteria even when it is essentially empty. There is no way to force users to add content to a map in this way.

CommentFileSizeAuthor
#8 1007462.patch1.26 KBsteinmb
#3 openlayers_cck_1007462.patch1.04 KBlevelos

Comments

tmcw’s picture

Title: Map widget with no content still generates WKT field data » CCK Field Requirements don't require features on map
Category: bug » feature

GEOMETRYCOLLECTION() is the minimum valid WKT generated by OpenLayers, when nothing is added to the map. Currently there is no support for dictating whether users add features to the map, given that this lies above the level of Drupal and the form api, and would require a bit of brittle code with uncertain requirements. Feel free to implement a behavior that checks that features are added - it's an afternoon project once you've learned the behaviors system.

figs’s picture

In case anyone encounters the same problem, my quick fix for this was to make an unpublished node (the unpublished node will not be accessible or be read by Views) with the WKT field containing the problematic "GEOMETRYCOLLECTION()" text, and preventing this from ever being duplicated by using the unique field module (http://drupal.org/project/unique_field). This prevents form validation for "empty" WKT fields.

levelos’s picture

Category: feature » bug
StatusFileSize
new1.04 KB

Hey gang - tmcw, I respectfully disagree that this is a feature request. This behavior makes it impossible to require an openlayers_cck field. At the least, users should be warned that you can't actually require the field.

Further, having a map feature with the coordinates set to GEOMETRYCOLLECTION() flat out breaks maps. It leads to an error on line 99 of openlayers.js, TypeError: Cannot call method 'transform' of undefined and a completely empty map page.

I'm not sure this is the best approach, but the attached patch solves the required field issue, at least for my use case. What wasn't obvious to me, is where the code that's inserting the empty GEOMETRYCOLLECTION() is located. Perhaps that would be a better area to find a solution.

tmcw’s picture

loubabe: Thanks for the patch. Can you reformat it as a CVS diff?

levelos’s picture

Status: Active » Needs review

tmcw, sorry, but I don't have a CVS checkout and don't have time now to grab it, reapply the patch, generate a new one, etc. In my experience, the git patch should apply cleanly to a CVS checkout. And I also heard something about a git migration happening in 2 days ;)

Status: Needs review » Needs work

The last submitted patch, openlayers_cck_1007462.patch, failed testing.

pgr1973’s picture

Instead of patching the 'openlayers_cck.module' to throw an error to user *after* submitting, one could also put some Javascript on the Page with the Input form, that checks before submitting the empty Field content. I did that on http://gmna.de, the js, that is inserted on the page with the input-form is this:

$(document).ready(function() {
  document.getElementById('node-form').onsubmit = valForm;
});

function valForm() {
  if(document.getElementById('edit-field-gp-openlayers-wkt').value == "GEOMETRYCOLLECTION()" || document.getElementById('edit-field-gp-openlayers-wkt').value == "") {
    alert("Bitte erst einen Punkt setzen.\nDazu das Stiftsymbol oben rechts\naktivieren und dann den Punkt setzen.\n\nPlease set a point first.\nTo set a point, activate the pen-icon\nat the top right and then set the point");
    return false;
  } else {
    return true;
  }
}

I putted this in an extra js-file in the theme directory and modified the 'template.php' so, that it inserts this js on the input-form-page for my content-type with the openlayers-maps. Trying to save an 'empty' Geomnesia-Point, you'll get an js-alert, telling you to set a point first ('edit-field-gp-openlayers-wkt' has to be the ID of the openlayers-wkt field).

That way, the user can't even submit the form, with no data (point) added. Because I don't want anonymous users to see any drupal-error-messages, the way with the patched 'openlayers_cck.module' was not appropriate.

Regards Paddy

steinmb’s picture

Version: 6.x-2.0-alpha10 » 6.x-2.x-dev
StatusFileSize
new1.26 KB

@pgr1973 thanx for a great usability tip, we might consider putting that one into a doc page somewhere?

Playing with the new recommanded patch format from Git, and rerolling the patch against the latest dev. code a73e982bb1f040192bfa138e153d954029412669

steinmb’s picture

Status: Needs work » Active

Git fun aside, is this patch still needed/valid? There is no way I'm able to create a node that contain a required OL field, if it's empty. Other problems related GEOMETRYCOLLECTION() do I also think are fixed:

  1. Editing a node that got a OL field that contain GEOMETRYCOLLECTION() no longer cause an OL error. This is fixed in the dev. release.
  2. Views with OL will blow up if you pass GEOMETRYCOLLECTION() or an empty field. You can avoid doing this by adding two filters in your Views data collector. One that make sure the field is not empty and another one that checks the content of the field, and make sure that it does not validate if the content is GEOMETRYCOLLECTION().

What is stopping us from rolling out alpha 11?

zzolo’s picture

Status: Active » Fixed

Thanks for the patch. I have not actually tested it, but the logic looks sound. It would be great if someone could confirm.
http://drupalcode.org/project/openlayers.git/commit/837c92c

As far as an alpha 11. Was hoping for an actual Beta, but not sure how stable things are. Also, most of the dev's have been working on the D7 version lately. Hopefully soon.

zzolo’s picture

Oh also, not that I think this is a high priority, but a better way to handle this is define GEMOTRYCOLLECTION() as the empty field. This would allow CCK to handle things better.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

diond’s picture

Thanks @pgr1973 for your JS suggestions. You saved my butt until I can get a better solution in place.