I'm using the lat/long widget, and when I choose to make it a "required field", it tries to validate the "default value" setting on saving the edit form and gives me the "required" error message. Presumably there is a way to tell validation that the default value isn't actually an instance of the form needing validated?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dpw’s picture

+1 making the field "required" in design view seems to require a default value to be added. I'm using the OpenLayers widget and Geofield 7.x-2.0-alpha2+7-dev (2013-Apr-06).

bechtold’s picture

+1 using 7.x-2.0-alpha2+9-dev
If you enter a default value, the validation is ok, but the default value is not saved :-)

geodaniel’s picture

Title: making field "required" » Cannot set field as "required" & default values not stored
Version: 7.x-2.0-alpha2 » 7.x-2.0

This is an issue in 2.0 as well.

Breakerandi’s picture

Issue summary: View changes

Any news on this? I have the issue still with the latest 2.1 version!!!

tisteegz’s picture

I am also experiencing this issue and I can confirm that when I entered in default values the validation worked but the values weren't saved. Which is somewhat of an issue if anyone does want default values.

DuaelFr’s picture

Version: 7.x-2.0 » 7.x-2.x-dev
Priority: Normal » Major
Status: Active » Needs review
FileSize
2.47 KB
2.12 KB

Here are two independant patches that fixes both issues.

  • The first one removes the check on emptiness in geofield_field_validate beaucause it was redundant with the one made by Drupal core with the hook_field_is_empty().
  • The second one uses the default_savlues stored in the field's instance to preset the widgets. The value was effectively stored but never displayed, even in the field configuration form.

I updated the priority to Major because not being able to set a field as required without giving it a default value (which is never displayed again) prevents users to use the field as they need to.

gge’s picture

I had a problem where the default values were not displayed on add node form and after applying #6 patches everything works now. The patches couldn't be applied automatically using Netbeans but I applied them manually.

Thank you!

das-peter’s picture

I had a similar or basically the same issue in the new openlayers / geofield integration.
The way I handled this was using '#limit_validation_errors' to completely disable the validation and the use $form_state['input'] instead $form_state['values'] to access the values for geocoding.
Not sure of this works for all scenarios - but as for now it's part of openlayers ;)
Related openlayers commit: http://cgit.drupalcode.org/openlayers/commit/?id=a380422

GaëlG’s picture

Status: Needs review » Reviewed & tested by the community

I can confirm that #6 fixes the bug. Thank you DuaelFr!

MissterX’s picture

Geofield version 7.x-2.3
#6, patch geofield-cannot_mark_field_as_required-1946058-6.patch
Confirmed as working.

brockfanning’s picture

Another report that one of the patches in #6, geofield-cannot_mark_field_as_required-1946058-6.patch works to fix the bug that Geofields cannot be set as required.

I wonder if the fact that there are 2 patches here might be confusing the issue and delaying this getting committed. I would vote for committing geofield-cannot_mark_field_as_required-1946058-6.patch. After applying that patch, I don't see any problems with either setting a Geofield as required, or giving it a default value.

In fact, I'll take the liberty of hiding the extra patch, but feel free to reverse that if I'm missing something.