Page MenuHomeSealhub

default-list-filters.ts
No OneTemporary

default-list-filters.ts

import { Field } from "sealious";
import { FlatTemplatable } from "tempstream";
export type ListFilterRender = (
value: string,
field: Field<any>
) => FlatTemplatable;
export type DefaultListFilter = {
render: ListFilterRender;
prepareValue?: (filter_value: unknown) => unknown;
};
export const BooleanListFilter = {
render: (value: string, field: Field<any>) => {
return /* HTML */ `<label>
${field.name}
<select name="filter[${field.name}]" autocomplete="off">
<option value="true" ${value == "true" ? "selected" : ""}>
True
</option>
<option value="false" ${value == "false" ? "selected" : ""}>
False
</option>
<option
value=""
${value == "null" ||
value == "" ||
value == "undefined" ||
value == undefined
? "selected"
: ""}
>
-
</option>
</select>
</label>`;
},
};
export const SimpleTextFilter = {
render: (value: string, field: Field<any>) => {
return /* HTML */ `<label>
${field.name}
<input
type="text"
name="filter[${field.name}]"
autocomplete="off"
${value ? `value="${value}"` : value}
/>
</label>`;
},
prepareValue: (value: string) => {
return { regex: `.*${value}.*` };
},
};
export const DefaultListFilters = {
boolean: BooleanListFilter,
text: SimpleTextFilter,
fallback: SimpleTextFilter,
} as Record<string, DefaultListFilter>;

File Metadata

Mime Type
text/x-java
Expires
Tue, Dec 24, 14:03 (18 h, 6 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
557252
Default Alt Text
default-list-filters.ts (1 KB)

Event Timeline