| [10:27:17] | <paul121[m]> | Trying to add a farmOS-map to a custom drupal page... but getting this error: |
| [10:27:21] | <paul121[m]> | `ReferenceError: google is not defined` |
| [10:28:06] | <paul121[m]> | The source is farmOS-map.js, I believe within the core `google.js` behavior |
| [10:28:46] | <paul121[m]> | I'm building the map with `farm_map_build()` in an AJAX callback. Might that cause problems? |
| [10:29:00] | <paul121[m]> | (I have Google Maps API key and it works on other pages) |
| [10:36:34] | <mstenta[m]> | <paul121[m] "I'm building the map with `farm_"> Yea this could be it |
| [10:36:52] | <mstenta[m]> | Can you paste example code? |
| [10:37:00] | <mstenta[m]> | When you say Ajax callback, do you mean in a Drupal Form API Ajax callback? |
| [10:37:42] | <mstenta[m]> | Generally Drupal Form API Ajax callbacks should not do any building of anything themselves |
| [10:37:55] | <mstenta[m]> | They should just return part of the form that needs to be replaced |
| [10:38:37] | <mstenta[m]> | And the form builder function itself is where the map itself should be built (conditionally based on $form_state if necessary) |
| [10:40:55] | <paul121[m]> | Ah okay. Yea, maybe I need to do some refactoring of that AJAX setup |
| [10:41:38] | <paul121[m]> | ACTION sent a long message: < https://matrix.org/_matrix/media/r0/download/matrix.org/XfmIKcwLSLVelWEg... > |
| [10:41:51] | <mstenta[m]> | Yea that's a common mistake. It's a bit unintuitive but everything needs to happen in the form builder function (the function that defines the form structure and fields) |
| [10:41:59] | <paul121[m]> | ACTION sent a long message: < https://matrix.org/_matrix/media/r0/download/matrix.org/vXTKwNXHotlDkCYs... > |
| [10:42:38] | <paul121[m]> | So... in this instance I want to select a farmOS area from a dropdown. Then load that single farm WKT into farmOS-map |
| [10:42:40] | <paul121[m]> | possible? |
| [10:42:56] | <mstenta[m]> | Yes possible |
| [10:42:56] | <paul121[m]> | I realize AJAX probably makes this much more complicated :-) |
| [10:43:26] | <mstenta[m]> | That shouldn't be hard |
| [10:43:59] | <mstenta[m]> | Basically need to have both the drop-down and the map in the _form() function |
| [10:44:51] | <mstenta[m]> | But then wrap the map in an if condition so it is only built if the drop-down value is set |
| [10:45:08] | * pllagn[m] has joined #farmos |
| [10:45:09] | <mstenta[m]> | Hard to describe on my phone :-) |
| [10:45:24] | <paul121[m]> | Yeah, that's what I have right now... |
| [10:45:47] | <mstenta[m]> | The other option... |
| [10:45:58] | <paul121[m]> | and the AJAX callback is set to `replace` a `div` that wraps the Map and other elements |
| [10:46:00] | <paul121[m]> | (in general that is working, it updates most of the form state) |
| [10:46:16] | <mstenta[m]> | Put a map on the page that always displays... And a js behavior that watches the drop-down and uses js to load/change the map geom |
| [10:46:38] | <mstenta[m]> | (no form Ajax in that approach) |
| [10:46:51] | <mstenta[m]> | Oh ok sounds like you do have it correct then |
| [10:47:13] | <mstenta[m]> | Can you paste the Ajax callback itself |
| [10:47:19] | <paul121[m]> | thats an interesting idea! |
| [10:47:40] | <mstenta[m]> | You can look at the area generator code for an example of that idea |
| [10:48:14] | <mstenta[m]> | (that actually uses a mix of form Ajax and js behavior) |
| [10:48:36] | <paul121[m]> | ACTION sent a long message: < https://matrix.org/_matrix/media/r0/download/matrix.org/lepbeAUajilAKsSi... > |
| [10:49:27] | <paul121[m]> | I have a couple other callbacks where some logic happens, and then they ultimately return the same element as this callback |
| [10:51:18] | <mstenta[m]> | ok yea that's good. should be simple |
| [10:51:37] | <mstenta[m]> | shouldn't have any logic in ajax callbacks, generally |
| [10:53:07] | <paul121[m]> | haha well maybe I've constructed this in a bit of an odd way |
| [10:54:10] | <paul121[m]> | anyways, what I have displays a map.... but there is jQuery error on the page so everything stops working |
| [10:54:30] | <paul121[m]> | (the jQuery error is the google not defined error) |
| [10:55:21] | <mstenta[m]> | hmm |
| [10:55:28] | <mstenta[m]> | it's possible that farmOS-map (or some of the farmOS-specific JS) is buggy in that regard (within AJAX replacement) |
| [10:56:16] | <mstenta[m]> | i'm curious what `google` is being reference though |
| [10:58:21] | <paul121[m]> | clicking on the error code takes me to this in the farmOS-map source: `mapTypeId:google.maps.MapTypeId.ROADMAP,` |
| [11:08:25] | <mstenta[m]> | oh ok |
| [11:08:28] | <mstenta[m]> | here's what happening: |
| [11:08:45] | <mstenta[m]> | the Google Maps JS is not being included (the one that lives on Google's servers) |
| [11:09:06] | <mstenta[m]> | https://github.com/farmOS/farmOS-map/#google-maps |
| [11:09:24] | <mstenta[m]> | `<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3&key=<KEY>"></script>` |
| [11:10:15] | <mstenta[m]> | that normally gets added here: https://github.com/farmOS/farmOS/blob/137f73a1d79460abcf17a9891203c0b3f4... |
| [11:10:34] | <mstenta[m]> | but that's probably not running the way it should when you are building the map ONLY via AJAX |
| [11:11:07] | <mstenta[m]> | i bet if you build the map unconditionally, and then replace it via ajax, it will work |
| [11:11:09] | <paul121[m]> | ahh! makes sense |
| [11:11:39] | <paul121[m]> | I also like your idea of replacing the WKT with a separate behavior... |
| [11:11:55] | <mstenta[m]> | yea could do that also... the farm_area_generate module is what to look at for that... |
| [11:11:55] | <paul121[m]> | any ideas on that? Specifically how to remove an existing WKT layer? |
| [11:12:00] | <mstenta[m]> | that's a bit of an "advance" ajax usage |
| [11:12:07] | <mstenta[m]> | yea check out that module |
| [11:12:12] | <paul121[m]> | cool |
| [11:12:27] | <mstenta[m]> | happy to answer specific questions! headed outside to do some house work |
| [11:12:34] | <mstenta[m]> | will check riot occassionally |
| [11:12:37] | <mstenta[m]> | good luck! |
| [11:12:49] | <paul121[m]> | cool! thanks! |
| [11:42:17] | * farmBOT has joined #farmos |
| [14:45:08] | <paul121[m]> | @mstenta question! |
| [14:45:36] | <paul121[m]> | trying to set `field_farm_data` in a `form_submit` |
| [14:46:24] | <paul121[m]> | I can set the `field_farm_notes`, but haven't seen any examples for `field_farm_data` ? |
| [14:46:30] | <paul121[m]> | ACTION sent a long message: < https://matrix.org/_matrix/media/r0/download/matrix.org/GcznlDSqFhtdUIcp... > |
| [15:06:26] | <mstenta[m]> | ``` $log_wrapper->field_farm_data->set(drupal_json_encode(array('tx' => $tx))); |
| [15:06:27] | <mstenta[m]> | ``` |
| [15:06:30] | <mstenta[m]> | Try that |
| [15:07:05] | <mstenta[m]> | The data field is just a plain text field, not a "formatted" text field like Notes |
| [15:07:28] | <mstenta[m]> | So it doesn't have sub fields for value and format |
| [15:07:36] | <mstenta[m]> | And will just save any text you put into it |
| [15:08:00] | <paul121[m]> | ohhh ok |
| [15:08:16] | <mstenta[m]> | You can use this to convert a var to JSON: https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_... |
| [15:08:44] | <mstenta[m]> | (basically just wraps PHPs own function) |
| [15:08:47] | <paul121[m]> | the db table `field_revision_field_farm_data` has column `field_farm_data_format` - does that just get set automatically? |
| [15:09:22] | <mstenta[m]> | Oh hmm, maybe I'm wrong |
| [15:09:44] | <mstenta[m]> | Maybe it is formatted, but yea you should just set it to plain_text |
| [15:10:15] | <mstenta[m]> | So try your code again, not mine, but convert to JSON first, and use plain text format |
| [15:10:45] | <mstenta[m]> | Hmm I feel like that's not right... |
| [15:10:51] | <mstenta[m]> | Try setting it without the format |
| [15:11:01] | <mstenta[m]> | Try my example :-) |
| [15:11:09] | <mstenta[m]> | Curious if it works |
| [15:11:37] | <paul121[m]> | haha okay I'll see what that does |
| [15:12:03] | <mstenta[m]> | It may just be that Drupal adds that format column regardless |
| [15:12:18] | <mstenta[m]> | Even if it's set to be an unformatted field |
| [15:15:41] | <paul121[m]> | your example worked! thanks!! |
| [15:39:45] | <mstenta[m]> | great! |
| [15:41:36] | <paul121[m]> | the `field_farm_data_format` column was set as `null` |
| [15:41:45] | <paul121[m]> | so maybe that can be set as well? |
| [15:47:29] | <mstenta[m]> | i wouldn't worry about it |
| [15:47:47] | <mstenta[m]> | look at your log/asset as JSON... does it include `value` and `format`? or is it just plain? |
| [15:47:55] | <mstenta[m]> | `/log/[id].json` |
| [15:48:45] | <paul121[m]> | doesn't include it |
| [15:48:48] | <paul121[m]> | 👍️ |
| [15:54:58] | <mstenta[m]> | awesome |