diff --git a/app/javascript/controllers/autocompleter_controller.js b/app/javascript/controllers/autocompleter_controller.js index 847081042e..a938a6b662 100644 --- a/app/javascript/controllers/autocompleter_controller.js +++ b/app/javascript/controllers/autocompleter_controller.js @@ -215,6 +215,13 @@ export default class extends Controller { } if (type == undefined) { return; } + let location = false; + if (detail.hasOwnProperty("request_params") && + detail.request_params.hasOwnProperty("lat") && + detail.request_params.hasOwnProperty("lng")) { + location = detail.request_params; + } + if (!AUTOCOMPLETER_TYPES.hasOwnProperty(type)) { alert("MOAutocompleter: Invalid type: \"" + type + "\""); } else { @@ -235,11 +242,13 @@ export default class extends Controller { !this.keepBtnTarget?.classList?.contains('active')) { this.clearHiddenId(); } - this.constrainedSelectionUI(); + this.constrainedSelectionUI(location); } } - constrainedSelectionUI() { + // Depending on the type of autocompleter, the UI may need to change. + // detail may also contain request_params for lat/lng. + constrainedSelectionUI(location = false) { if (this.TYPE === "location_google") { this.verbose("autocompleter: swapped to location_google"); this.element.classList.add('create'); @@ -250,7 +259,7 @@ export default class extends Controller { } else { this.verbose("autocompleter: no map wrap"); } - this.activateMapOutlet(); + this.activateMapOutlet(location); } else if (this.ACT_LIKE_SELECT) { this.verbose("autocompleter: swapped to ACT_LIKE_SELECT"); this.deactivateMapOutlet(); @@ -272,7 +281,7 @@ export default class extends Controller { } // Connects the location_google autocompleter to call map controller methods - activateMapOutlet() { + activateMapOutlet(location = false) { if (!this.hasMapOutlet) { this.verbose("autocompleter: no map outlet"); return; @@ -289,13 +298,13 @@ export default class extends Controller { // set the map to stop ignoring place input this.mapOutlet.ignorePlaceInput = false; - // 2024-08-09: Don't geocode lat/lng when switching to location_google. - // This is for custom locations and should pay attention to place_name only. - // let location - // if (location = this.mapOutlet.validateLatLngInputs(false)) { - // this.mapOutlet.tryToGeocode(); - // } else - if (this.mapOutlet.hasLockBoxBtnTarget) { + // 2024-08-09: Unless the swap call (form-exif) sent request_params lat/lng, + // don't geocode lat/lng when switching to location_google. Usually, this is + // for geolocating place_names and should pay attention to text only. + if (location) { + // this.mapOutlet.geocodeLatLng(location); + this.mapOutlet.tryToGeocode(); + } else if (this.mapOutlet.hasLockBoxBtnTarget) { this.mapOutlet.lockBoxBtnTarget.classList.remove("d-none"); } } diff --git a/test/system/observation_form_system_test.rb b/test/system/observation_form_system_test.rb index f9b73bde5f..14113ff5a0 100644 --- a/test/system/observation_form_system_test.rb +++ b/test/system/observation_form_system_test.rb @@ -385,6 +385,8 @@ def test_post_edit_and_destroy_with_details_and_location all('[id^="project_id_"]', visible: :all).each do |project_checkbox| project_checkbox.trigger("click") if project_checkbox.checked? end + step_nav_3 = find("#step-nav-3") + within(step_nav_3) { click_on(:BACK.l) } # submit_observation_form_with_errors within("#observation_form") { click_commit }