0

The code below successfully updates the title, but does not update the Geofield. The node_save function is provide by DrupalGap and described here http://api.drupalgap.org/node.js_.html

        var node = {
            'nid': nid,
            title : 'New Title', // THIS WORKS!!
            'field_geocoordinates[und][0][geom][lat]':tripchi.geocoordinates.coords.latitude.toString(), // NONE OF THESE DO
            'field_geocoordinates[und][0][geom][lon]':tripchi.geocoordinates.coords.longitude,
            'field_geocoordinates[und][0][geom][lat]':tripchi.geocoordinates.coords.latitude, 
            'field_geocoordinates[und][0][geom][lat]':tripchi.geocoordinates.coords.latitude.toString(), 
            'field_geocoordinates["und"][0]["geom"]["lat"]':tripchi.geocoordinates.coords.latitude.toString(),
            'field_geocoordinates["und"][0]["geom"]["lon"]':tripchi.geocoordinates.coords.longitude.toString(),
            'field_deal_count[und][0][value]' : 3, // simpler structure also does not update
            "field_geocoordinates": {
                "und": [
                    {
                        "geom": "POINT (2 1)",
                        "geo_type": "point",
                        "lat": tripchi.geocoordinates.coords.latitude.toString(), // I've tried this as strings and integers
                        "lon": tripchi.geocoordinates.coords.longitude.toString(),
                        "left": "2.000000000000",
                        "top": "1.000000000000",
                        "right": "2.000000000000",
                        "bottom": "1.000000000000",
                        "geohash": "s01m"
                    }
                ]
            }
        };
        node_save(node, {
            success: function(result) {
                console.log(result);
                utils.mAlert("Pinpointed Location to Latitude:" + tripchi.geocoordinates.coords.latitude + ' - Longitutde:' + tripchi.geocoordinates.coords.longitude);
            }, error: function(result) {
                utils.mAlert("UPDATE ERROR: " + result);
                console.log(result);
            }
        });

How should i be targeting custom fields in custom html forms / ajax update requests?

UPDATE: @Jimajamma is correct in the comment below, but this only works when the property to update is value. It is not working on the Geofield module object shown in my code above.

2 Answers 2

0

From this example it looks like the syntax is along these lines:

var node = {
  type:"donation",
  title:"Donation",
  field_donation_amount: {
    und: {
      0: {
        value: form_state.values.amount,
      },
    },
  },
};

Addition:

So have you looked at something like this then? Nesting things further, eg:

var node = {
  field_geocoordinates: {
    und: {
         0: {
            geom: {
                  lat: FOO,
            },
         },
    },
  },
};

(I think I have the correct number of }s :) Perhaps a js version of php's print_r (here is an example) of a valid node object from node_load() would help out?

4
  • thank you. update does work when the property is 'value'. i tested it does not matter if 'und' is an object or array format. Any ideas on updating the more complex GeoPoint structure?
    – E.A.T
    Commented Jun 28, 2014 at 19:30
  • I think you forgot the 0 in your structure
    – Jimajamma
    Commented Jun 29, 2014 at 11:34
  • i f$&#ing love you!
    – E.A.T
    Commented Jun 29, 2014 at 15:13
  • I guess it's the same as the array format described here: drupal.org/node/1854188
    – Sam Wilson
    Commented Dec 11, 2014 at 4:41
0

The solution to create geofield by lat and lot

include_once(drupal_get_path("module", "geophp") . "/geoPHP/lib/geometry/Geometry.class.php"); include_once(drupal_get_path("module", "geophp") . "/geoPHP/lib/geometry/Point.class.php");

$node->field_current_location['und'][0]['geom'] = new point((float)$lat, (float)$lot);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.