Page MenuHomeSealhub

single-reference.ts
No OneTemporary

Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None

single-reference.ts

import { FieldTypes as SealiousFieldTypes } from "sealious";
import { CollectionField } from "../fields/collection-field.js";
import { DropdownOptions, FreeformDropdown } from "./dropdown.js";
import { Collection, CollectionItem } from "sealious";
export class SingleReferenceDropdown<
TargetCollection extends Collection,
F extends SealiousFieldTypes.SingleReference,
Required extends boolean,
> extends FreeformDropdown {
constructor(
public field: CollectionField<F, Required>,
public options: DropdownOptions & {
getLabel?: (item: CollectionItem<Collection>) => string;
} = {
label: field.label || field.name,
autosubmit: false,
autocomplete: true,
}
) {
super(
field,
async (ctx) => {
const { items } = await ctx.$app.collections[
field.sealiousField.target_collection
]
.list(ctx.$context)
.fetch();
return [
{ value: "", label: "--" },
...items.map((item) => ({
value: item.id,
label: options.getLabel
? options.getLabel(item)
: item.id,
})),
];
},
options
);
}
setOptionLabelGetter(
getter: (item: CollectionItem<TargetCollection>) => string
): this {
this.options.getLabel = getter;
return this;
}
}

File Metadata

Mime Type
application/javascript
Expires
Fri, Nov 27, 16:16 (1 d, 14 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1200170
Default Alt Text
single-reference.ts (1 KB)

Event Timeline