Skip to content

Commit

Permalink
fix: make multi-select static work
Browse files Browse the repository at this point in the history
fixes #63
  • Loading branch information
danielo515 committed Oct 11, 2023
1 parent e523b1f commit fa5987a
Show file tree
Hide file tree
Showing 4 changed files with 388 additions and 397 deletions.
2 changes: 1 addition & 1 deletion src/FormModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class FormModal extends Modal {
{
this.formResult[definition.name] = this.formResult[definition.name] || []
const options = fieldInput.source == 'fixed'
? fieldInput.options
? fieldInput.multi_select_options
: get_tfiles_from_folder(fieldInput.folder, this.app).map(file => file.basename);
this.svelteComponents.push(new MultiSelect({
target: fieldBase.controlEl,
Expand Down
8 changes: 6 additions & 2 deletions src/core/formDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type inputSelectFixed = {
options: { value: string; label: string }[];
}
type basicInput = { type: FieldType };
type multiselect = { type: 'multiselect', source: 'notes', folder: string } | { type: 'multiselect', source: 'fixed', options: string[] }
type multiselect = { type: 'multiselect', source: 'notes', folder: string } | { type: 'multiselect', source: 'fixed', multi_select_options: string[] }
type inputType =
| basicInput
| inputNoteFromFolder
Expand Down Expand Up @@ -120,6 +120,7 @@ export type EditableInput = {
min?: number;
max?: number;
options?: { value: string; label: string }[];
multi_select_options?: string[];
query?: string;
};

Expand All @@ -145,7 +146,10 @@ export function isMultiSelect(input: unknown): input is multiselect {
return isObject(input)
&& input.type === 'multiselect'
&& (
(input.source === 'notes' && typeof input.folder === 'string') || (input.source === 'fixed' && Array.isArray(input.options))
(input.source === 'notes' && typeof input.folder === 'string')
|| (
input.source === 'fixed' && Array.isArray(input.multi_select_options) && input.multi_select_options.every((option: unknown) => typeof option === 'string')
)
)
}

Expand Down
2 changes: 1 addition & 1 deletion src/exampleModalDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const exampleModalDefinition: FormDefinition = {
name: "multi_example_2",
label: "Multi select fixed",
description: "Allows to pick many notes from a fixed list",
input: { type: "multiselect", source: "fixed", options: ['Android', 'iOS', 'Windows', 'MacOS', 'Linux', 'Solaris', 'MS2'] },
input: { type: "multiselect", source: "fixed", multi_select_options: ['Android', 'iOS', 'Windows', 'MacOS', 'Linux', 'Solaris', 'MS2'] },
},
{
name: "best_fried",
Expand Down
Loading

3 comments on commit fa5987a

@theotheo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was playing with your code and encountered the issue that the entered select values disappeared. As I understood, the problem is that field.input.options is no longer used (line 235 FormBuilder.svelte). Furthermore, I noticed that the formats for options in select and multiselect are different. multi_select_options is an array of strings, while select is an array of objects with label/value pairs. Sorry, but are you sure this will work correctly?

@danielo515
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was playing with your code and encountered the issue that the entered select values disappeared.

The select and multi-select are two different fields. If you are seeing that in the select it's a bug on the select one, but as far as I'm testing, the select just works

@theotheo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to explain my observations better: #75

Please sign in to comment.