]> git.openstreetmap.org Git - nominatim-ui.git/blob - src/components/UrlSubmitForm.svelte
Handle all page changes via page store (#70)
[nominatim-ui.git] / src / components / UrlSubmitForm.svelte
1 <script>
2   import { refresh_page } from '../lib/stores.js';
3
4   export let page;
5
6   function serialize_form(form) {
7     var params = new URLSearchParams();
8
9     Array.prototype.slice.call(form.elements).forEach(function (field) {
10       if (!field.name || field.disabled || ['submit', 'button'].indexOf(field.type) > -1) return;
11
12       if (['checkbox', 'radio'].indexOf(field.type) > -1 && !field.checked) return;
13       if (typeof field.value === 'undefined' || field.value === '') return;
14
15       params.set(field.name, field.value);
16     });
17
18     return params;
19   }
20 </script>
21
22 <form on:submit|preventDefault={(e) => refresh_page(page, serialize_form(e.target))} class="form-inline" role="search" accept-charset="UTF-8" action="">
23     <slot></slot>
24 </form>