Closed flightsurvey closed 7 years ago
It seems the jQuery form_element.submit()
causes a page reload.
Below a non-jQuery solution
Open http://rawgit.com/opencagedata/leaflet-opencage-search/master/demo/index.html in Google Chrome and open the developer console
// opens the search field
document.querySelector('.leaflet-control-ocd-search-icon').click();
// fills the search field
document.querySelector('.leaflet-control-ocd-search-form input').setAttribute('value','Notting Hill');
// submits the form
var submit_event = document.createEvent('HTMLEvents');
submit_event.initEvent('submit', true, false);
document.querySelector('.leaflet-control-ocd-search-form').dispatchEvent(submit_event);
Perfect! Worked first time - you are a star.
I have adapted the code so that the container, form and input now have IDs:
Which results in:
I am using standard jquery to add the "leaflet-control-ocd-search-expanded" class to the container and populate the input from a value in another form:
Which works OK but, despite trying to force a form submit and simulating keypress (enter) on the input, I cannot get the search to activate.
Do you have an idea as to how it could be done?
Many thanks