Working on a creating a custom CRS Leaflet map. On map rightclick, show a popup with select boxes for users interaction.
var submit_Loc_popup = L.popup();
map.on('contextmenu', onPopupBoxSubmit);
var featureGroup = L.featureGroup().addTo(map);
I have the select box's hidden, until something is chosen, shown here Fiddle#1: https://jsfiddle.net/ay9pso8L/
I'd like to have those select options inserted into my maps popupContent. Unsuccessfully tried different ways but nothing produces the JSfiddles clean selects/hidden content... I manually created the Div + select(s) with a gigantic HTML string, but I'm unable to hide content as they are embedded in quotes since it's a string... JSFiddle #2 Here: https://jsfiddle.net/0x16zqkc/
Excerpt from JSfiddle#2;
function onPopupBoxSubmit(eb) {
var xy = map.project([eb.latlng.lat,eb.latlng.lng],6);
console.log(xy);
var coords3 = convertToInGameCords(xy);
console.log(coords3);
var popupContent = <seeJSFiddle#2 for HTML>
submit_Loc_popup
.setLatLng(eb.latlng)
.setContent(popupContent + '"x": ' +coords3.y+', "y": '+coords3.x)
.openOn(map);
};
Reading the documentation: https://leafletjs.com/reference-1.4.0.html#popup-setcontent Maybe I've tried a function to create the DIV and pass that in but its still not modifiable.
I've been researching for a week and this Answer is somewhat similar to what I want... Kind of, but its for a marker and when I tried to do that with the popUpcontent it didn't work. Dynamically create leaflet popup via JavaScript Object
Long story short;
How can I merge JS fiddle#1 hidden_select_(#node_resource) into JS Fiddle#2's popup.setContent()?
EDIT#1 Based on Toms reply, JS Fiddle updated
https://jsfiddle.net/q5cdhw3e/1/
Drop downs are working when including the handlers INSIDE a mymap.on('popupopen',
However, my onSubmit is not working, I will dig around to see what I can find.
EDIT#2 JS Fiddle updated https://jsfiddle.net/Ls1zax5c/
Placing the eventlistener first solved the on_submit problem
document.querySelector("#node_submission_form2").addEventListener("submit", function(e) {