< 182020-04-19⋎20 >

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

< 182020-04-19⋏20 >