<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>