Hi there, I have a complex d7 wizard forms interface that allows my users a pain free easy to use way to put data into my system, this seriously improves this process over the usual node entry form. The problem is my lat long format.
I am putting data successfully into a geofield by prepoulating the fields in my object, then saving, this works great if I input in d.d but when I use the dms format it wont let me, here is my d.d approach.
// Lets create one.
// Build new node framework.
$new_location_node = new stdClass();
$new_location_node->type = 'sparcs_station_location';
node_object_prepare($new_location_node);
$new_location_node->title = $form_state['object']['location_name'];
$new_location_node->language = LANGUAGE_NONE;
$new_location_node->station_location_elevation['und'][0]['value'] = $form_state['object']['location_ele'];
$lat = $form_state['object']['location_lat'];
$lon = $form_state['object']['location_lon'];
$new_location_node->station_location_lat_lon ['und'][0]['geo_type'] = 'point';
$new_location_node->station_location_lat_lon ['und'][0]['lat'] = $lat;
$new_location_node->station_location_lat_lon ['und'][0]['lon'] = $lon;
I then go on to save the node and presto,
However, when my users decide to put DMS in instead, it chokes and makes a silly entry, so does this mean I will have to decode the DMS myself then put D.D in or can I leverage the good work you have done to make it understand sloppy DMS somehow?
THanks
Keep up the good work. My major D7 project SPARCS 2012 will rely heavily on geofield.
Franco Nogarin
Comments
Comment #1
phayes commentedYou'll want to pass everything via geofield_latlon_DMStoDEC() first.
Comment #2
spydmobile commentedThanks Patrick!!!
I will get that in there and report back :)
Franco
Comment #3
spydmobile commentedFor those intrested in how I implemented my geofield in a custom wizard, I did it in the form with a couple small helpers. here are the form elements:
Here are the two helper callback functions
The end result is wonderful, the user types in the DMS values and they automagically change to DD. when you move to the next field!
Thanks again Patrick!
Comment #4
hutch commentedInteresting, you might be able to improve on the callbacks using one of the functions described in ajax_commands, perhaps function ajax_command_replace(). $selector would be "#edit-location-lon" and $html the converted value, eg $longitude in your example. This would avoid reprinting the actual form element.
Comment #5
spydmobile commentedthanks @hutch for taking an interest and offering your suggestions :) I tried your suggestion like this:
it still nuked the form element. but the use of the # in the selector makes me wonder, since the examples do not use the # in the selector, so I tried without and it still nuked the form element. In fact (I might be wrong)I think that my form element array already does exactly what you are suggesting:
I think its because this function is not meant to target the input element but rather other elements on the page like the description or the title, either way it seems like cool voodoo to me, wish I had a better handle on it, I tore apart the ajax_example_module but nothing in there replaces itself like mine is :(
Franco
Comment #6
hutch commentedThere doesn't seem to be a way of using jQuery's .val() on a form element so your way will have to do.
Still, '#ajax' is an interesting feature of form building that I should explore more fully, so far I have always just written some js, used $.get() to fetch anything from the server and so on.
Comment #7
spydmobile commentedExactly, and using #ajax is a bit more .... Drupalish? :)
Thanks again for your time! I am the only dev on the project, and it is huge (Well to me anyhow) so I appreciate any input or ideas!
Cheers
Franco