diff --git a/resources/js/Components/Pages/RecordsPage.tsx b/resources/js/Components/Pages/RecordsPage.tsx index 864644795..feb7cef4e 100644 --- a/resources/js/Components/Pages/RecordsPage.tsx +++ b/resources/js/Components/Pages/RecordsPage.tsx @@ -507,7 +507,15 @@ export class RecordsPage extends Page { // (temporary) .first((s) => field.id in s.fields); .filter((s) => field.id in s.fields) .first(); - let {options} = section.fields[field.id] as SelectT; + + const select = section.fields[field.id] as SelectT; + let {options} = select; + const {model, labelAttribute} = select; + + if (model && labelAttribute) { + options = this.getModelSelectOptions(model, labelAttribute); + } + if (options instanceof Promise) { options = await options; } @@ -541,7 +549,10 @@ export class RecordsPage extends Page { return list.join(''); } - async getModelSelectOptions(model: typeof Model, labelAttribute: string): Promise { + async getModelSelectOptions( + model: typeof Model, + labelAttribute: string + ): Promise { const response = await model.all(); const categories = response.getData(); diff --git a/resources/js/typings/forms.ts b/resources/js/typings/forms.ts index 117860dee..b81411a46 100644 --- a/resources/js/typings/forms.ts +++ b/resources/js/typings/forms.ts @@ -6,6 +6,7 @@ import { } from '@material/mwc-textfield'; import {MaterialIcons} from './icons'; +import {Model} from '../Models'; export interface FieldT { id?: string @@ -85,5 +86,7 @@ export type SelectT = FieldT & { selected?: ListItemBase | null items?: ListItemBase[] index?: number - options?: SelectOptionsT | Promise + options?: SelectOptionsT | Promise, + model?: typeof Model, + labelAttribute?: string };