]> git.openstreetmap.org Git - nominatim-ui.git/blobdiff - src/components/UrlSubmitForm.svelte
allow theming (#84)
[nominatim-ui.git] / src / components / UrlSubmitForm.svelte
index f902f70dc3cba8d62ccbd4d6480edf27ffead0f5..019fa8c9f007b1932bc3ac8d42e365a75d150e8c 100644 (file)
@@ -1,18 +1,24 @@
 <script>
-  import { serialize_form, clean_up_url_parameters } from '../lib/api_utils.js';
   import { refresh_page } from '../lib/stores.js';
 
-  function handleSubmit(event) {
-    event.preventDefault();
+  export let page;
 
-    var target_url = serialize_form(event.target);
-    target_url = clean_up_url_parameters(target_url);
+  function serialize_form(form) {
+    var params = new URLSearchParams();
 
-    window.history.pushState({}, '', '?' + target_url);
-    refresh_page();
+    Array.prototype.slice.call(form.elements).forEach(function (field) {
+      if (!field.name || field.disabled || ['submit', 'button'].indexOf(field.type) > -1) return;
+
+      if (['checkbox', 'radio'].indexOf(field.type) > -1 && !field.checked) return;
+      if (typeof field.value === 'undefined' || field.value === '') return;
+
+      params.set(field.name, field.value);
+    });
+
+    return params;
   }
 </script>
 
-<form on:submit={handleSubmit} class="form-inline" role="search" accept-charset="UTF-8" action="">
-    <slot></slot>
+<form on:submit|preventDefault={(e) => refresh_page(page, serialize_form(e.target))} class="form-inline" role="search" accept-charset="UTF-8" action="">
+  <slot></slot>
 </form>