According to https://www.drupal.org/node/1231390 the geoloaction field (drupal 8 version) is not validated even it is marked as required:

When switching on the 'required field' checkbox in a Geolocation field's settings, the field is not required anyhow.
The lat/lon can be empty, without being 'noticed' by the default drupal checks.

If I don't set any value, I can submit the form, although it is required. This leads to the error "This value should be null.", which is not field specific and unhelpful for the user ("I don't know, what's wrong with my inputs?!").

Comments

pminf created an issue. See original summary.

pminf’s picture

Issue summary: View changes

fixed typo

christianadamski’s picture

Hey pminf,

1.) As mentioned in your linked issue, submitting empty lat / lng values despite field being required was already fixed.
2.) The required empty field is highlighted as erroneous, so it's not like the user has no idea what's happening.

I agree the message is not as helpful as it could be.

christianadamski’s picture

Do you use the default widget to input your data?

christianadamski’s picture

Status: Active » Fixed

Added "#required" parameters to the lat/lng widget. It will now correctly state the field names that are missing, as well as indicate that little red *.

pminf’s picture

Status: Fixed » Needs work
StatusFileSize
new77.33 KB

Sorry for the missing information. I opened this issue because it seemed to be fixed in version 7.x but not in 8.x. It might be related to the Geolocation Google Geocoder widget.

W've checked your last fix but it didn't work.

Steps to reproduce on simplytest.me:

  1. Create project of geolocation 8.x-1.5 with English standard profile.
  2. Install module geolocation.
  3. Add field geolocation to node type basic page.
  4. Set it as required field and choose form display widget Geolocation Google Geocoder.
  5. Create new Basic Page without setting the coordinates

You get the error message "This value should not be null." and the geolocation field is not marked as invalid (see screenshot).

christianadamski’s picture

Status: Needs work » Fixed

Please test again with the latest 8.x-1.x-DEV release. The 8.x-1.5 branch does not contain any of these changes.

pminf’s picture

Status: Fixed » Needs work

I've tested the 8.x-1.x branch on simplytest.me which equates to the 8.x-1.x-DEV release. Same problem here.

christianadamski’s picture

Ooooh, we're talking about the geocoder widget now. Yeah ok, I was talking about the default one. Yeah ok.

christianadamski’s picture

christianadamski’s picture

Title: Making a Geolocation field 'required field' » Making a Geolocation field 'required field' in all widgets
christianadamski’s picture

Status: Needs work » Needs review
StatusFileSize
new1.55 KB
christianadamski’s picture

christianadamski’s picture

Added more appropriate messages for geocoder widget and HTML5 widget.

christianadamski’s picture

Added tests as well.

  • ChristianAdamski committed 871b2a3 on 8.x-1.x
    Issue #2748363 by ChristianAdamski, pminf: Making a Geolocation field '...
christianadamski’s picture

Status: Needs review » Fixed

Status: Fixed » Needs work

christianadamski’s picture

Status: Needs work » Fixed

Failure is ok. I already committed this, so Patches do not apply anymore.

pminf’s picture

Thank you! Serverside validation now seems to work as expected. But what about clientside validation? If I don't set a value, I should not be able to submit the form (like required plain text or file upload fields).

Status: Fixed » Closed (fixed)

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