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