From 709a40b36e7bff0a687cc40f2359cbab897c01a9 Mon Sep 17 00:00:00 2001
From: Jaime Herencia <jherencia@360690.no-reply.drupal.org>
Date: Wed, 8 Aug 2012 17:15:57 +0200
Subject: [PATCH] Issue #1717860 by jherencia: Lat/lng and bounds widget does
 not alert users to fill every input in case they fill at
 least one.

---
 geofield.elements.inc |   30 ++++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/geofield.elements.inc b/geofield.elements.inc
index fecc628..79b8bc9 100644
--- a/geofield.elements.inc
+++ b/geofield.elements.inc
@@ -122,6 +122,8 @@ function geofield_latlon_element_validate($element, &$form_values) {
     ),
   );
 
+  $allFilled = TRUE;
+  $anyFilled = FALSE;
   foreach ($components as $key => $component) {
     if (!empty($element[$key]['#value'])) {
       if (!is_numeric($element[$key]['#value'])) {
@@ -131,6 +133,19 @@ function geofield_latlon_element_validate($element, &$form_values) {
         form_error($element[$key], t('@title: @component_title is out of bounds.', array('@title' => $element['#title'], '@component_title' => $component['title'])));
       }
     }
+    if ($element[$key]['#value'] == '') {
+      $allFilled = FALSE;
+    }
+    else {
+      $anyFilled = TRUE;
+    }
+  }
+  if ($anyFilled && !$allFilled) {
+    foreach ($components as $key => $component) {
+      if ($element[$key]['#value'] == '') {
+        form_error($element[$key], t('@title: @component_title must be filled too.', array('@title' => $element['#title'], '@component_title' => $component['title'])));
+      }
+    }
   }
 }
 
@@ -211,6 +226,8 @@ function geofield_bounds_element_validate($element, &$form_values) {
     ),
   );
 
+  $allFilled = TRUE;
+  $anyFilled = FALSE;
   foreach ($components as $key => $component) {
     if (!empty($element[$key]['#value'])) {
       if (!is_numeric($element[$key]['#value'])) {
@@ -220,6 +237,19 @@ function geofield_bounds_element_validate($element, &$form_values) {
         form_error($element[$key], t('@title: @component_title is out of bounds.', array('@title' => $element['#title'], '@component_title' => $component['title'])));
       }
     }
+    if ($element[$key]['#value'] == '') {
+      $allFilled = FALSE;
+    }
+    else {
+      $anyFilled = TRUE;
+    }
+  }
+  if ($anyFilled && !$allFilled) {
+    foreach ($components as $key => $component) {
+      if ($element[$key]['#value'] == '') {
+        form_error($element[$key], t('@title: @component_title must be filled too.', array('@title' => $element['#title'], '@component_title' => $component['title'])));
+      }
+    }
   }
 }
 
-- 
1.7.5.4

