diff --git a/src/API.ts b/src/API.ts index 3a7db195..d1e9e2a2 100644 --- a/src/API.ts +++ b/src/API.ts @@ -102,28 +102,36 @@ export class API { } } - public limitedForm(name: string, opts: limitOptions): Promise { + /** + * Opens a named form, limiting/filtering the fields included + * @param {string} name - The name of the form to open + * @param {limitOptions} limitOpts - The options to apply when filtering fields + * @param {FormOptions} formOpts - Form options to use when opening the form once filtered + * @returns {Promise} - A promise that resolves with the form result + * @throws {ModalFormError} - Throws an error if the form definition is not found + */ + public limitedForm(name: string, limitOpts: limitOptions, formOpts?: FormOptions): Promise { const formDefinition = this.getFormByName(name); let newFormDefinition: FormDefinition; if (formDefinition) { - if (isOmitOption(opts)) { - const omit = opts.omit; + if (isOmitOption(limitOpts)) { + const omit = limitOpts.omit; newFormDefinition = { ...formDefinition, fields: formDefinition.fields.filter((field) => !omit.includes(field.name)), }; - } else if (isPickOption(opts)) { + } else if (isPickOption(limitOpts)) { newFormDefinition = { ...formDefinition, fields: formDefinition.fields.filter((field) => opts.pick.includes(field.name)), }; } else { throw new ModalFormError( - "Invalid options provided to limitedForm", - `GOT: ${JSON.stringify(opts)}`, + "Invalid limit options provided to limitedForm", + `GOT: ${JSON.stringify(limitOpts)}`, ); } - return this.openModalForm(newFormDefinition); + return this.openModalForm(newFormDefinition, formOpts); } else { const error = new ModalFormError(`Form definition ${name} not found`); log_error(error);