fix: View filter - handle change of field type
This commit is contained in:
parent
2d80b2be3d
commit
e6c8ca44c5
|
@ -98,6 +98,22 @@
|
||||||
function isDate(field) {
|
function isDate(field) {
|
||||||
return viewModel.schema[field].type === "datetime"
|
return viewModel.schema[field].type === "datetime"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isNumber(field) {
|
||||||
|
return viewModel.schema[field].type === "number"
|
||||||
|
}
|
||||||
|
|
||||||
|
const fieldChanged = filter => ev => {
|
||||||
|
// reset if type changed
|
||||||
|
if (
|
||||||
|
filter.key &&
|
||||||
|
ev.target.value &&
|
||||||
|
viewModel.schema[filter.key].type !==
|
||||||
|
viewModel.schema[ev.target.value].type
|
||||||
|
) {
|
||||||
|
filter.value = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div bind:this={anchor}>
|
<div bind:this={anchor}>
|
||||||
|
@ -124,7 +140,11 @@
|
||||||
{/each}
|
{/each}
|
||||||
</Select>
|
</Select>
|
||||||
{/if}
|
{/if}
|
||||||
<Select secondary thin bind:value={filter.key}>
|
<Select
|
||||||
|
secondary
|
||||||
|
thin
|
||||||
|
bind:value={filter.key}
|
||||||
|
on:change={fieldChanged(filter)}>
|
||||||
<option value="">Choose an option</option>
|
<option value="">Choose an option</option>
|
||||||
{#each fields as field}
|
{#each fields as field}
|
||||||
<option value={field}>{field}</option>
|
<option value={field}>{field}</option>
|
||||||
|
@ -138,6 +158,7 @@
|
||||||
</Select>
|
</Select>
|
||||||
{#if filter.key && isMultipleChoice(filter.key)}
|
{#if filter.key && isMultipleChoice(filter.key)}
|
||||||
<Select secondary thin bind:value={filter.value}>
|
<Select secondary thin bind:value={filter.value}>
|
||||||
|
<option value="">Choose an option</option>
|
||||||
{#each fieldOptions(filter.key) as option}
|
{#each fieldOptions(filter.key) as option}
|
||||||
<option value={option}>{option.toString()}</option>
|
<option value={option}>{option.toString()}</option>
|
||||||
{/each}
|
{/each}
|
||||||
|
@ -146,6 +167,12 @@
|
||||||
<DatePicker
|
<DatePicker
|
||||||
bind:value={filter.value}
|
bind:value={filter.value}
|
||||||
placeholder={filter.key || fields[0]} />
|
placeholder={filter.key || fields[0]} />
|
||||||
|
{:else if filter.key && isNumber(filter.key)}
|
||||||
|
<Input
|
||||||
|
thin
|
||||||
|
bind:value={filter.value}
|
||||||
|
placeholder={filter.key || fields[0]}
|
||||||
|
type="number" />
|
||||||
{:else}
|
{:else}
|
||||||
<Input
|
<Input
|
||||||
thin
|
thin
|
||||||
|
|
Loading…
Reference in New Issue