Skip to content

Commit 28352f1

Browse files
authored
feat: add option to disable dropdown form item (#403)
* feat: add option to disable dropdown form item * feat: add documentation for disabling dropdown
1 parent 8c60935 commit 28352f1

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

docs/DATAMODEL.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,7 @@ type DropdownFormItem = BaseFormItem & {
11921192
value: string;
11931193
label: string;
11941194
}>;
1195+
disabled?: boolean;
11951196
};
11961197

11971198
type Stars = BaseFormItem & {
@@ -2808,15 +2809,17 @@ interface ChatItemFormItem {
28082809
value: string;
28092810
label: string;
28102811
}>;
2812+
disabled?: boolean; // this is only applicable to DropDownFormItem. If this is set to true, the dropdown is disabled. User cannot use the dropdown.
28112813
}
28122814
```
28132815

28142816
Since you can give unlimited form items with several different types, it might be good to know that some attributes are only applicable to some types. Like `options` attribute is only getting used by `select` and `radiogroup` items. Or `placeholder` is only getting used by `textarea`, `textinput` and `numericinput`.
28152817

28162818
`validationPattenrs` works only for textual inputs. You can define one or more validation regex patterns, use an operator between them as `AND` or `OR`. You can show individual error messages for each validation or use one generic message if the combined validation fails (Might be useful for `OR` operator).
28172819

2818-
**Another thing which might be interesting** is to know that if you set the `select` or the `radiogroup` mandatory, they'll be rendered as the first item's of them selected if you don't provide an initial value. And you cannot deselet a radio item in any case. For select, if it is mandatory there won't be the option `Please select...`
2820+
**Another thing which might be interesting** is to know that if you set the `select` or the `radiogroup` mandatory, they'll be rendered as the first item's of them selected if you don't provide an initial value. And you cannot deselet a radio item in any case. For select, if it is mandatory there won't be the option `Please select...`.
28192821

2822+
**Important note for DropdownFormItem:** If you set `disabled` to `true` for `DropdownFormItem`, the dropdown will be disabled and the user cannot interact with it. When you have a default value and want to ensure it's always displayed, you can combine `mandatory: true` with `disabled: true` - this will automatically select and display the first value in `options` while preventing user interaction.
28202823

28212824
_**NOTE**: If you set `options` for `textinput` for example, it won't affect the textinput to be rendered and work properly._
28222825

src/components/chat-item/chat-item-form-items.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ export class ChatItemFormItemsWrapper {
110110
placeholder: chatItemOption.placeholder ?? Config.getInstance().config.texts.pleaseSelect,
111111
...(this.getHandlers(chatItemOption))
112112
});
113+
if (chatItemOption.disabled === true) {
114+
chatOption.setEnabled(false);
115+
}
113116
break;
114117
case 'radiogroup':
115118
case 'toggle':

src/static.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ type DropdownFormItem = BaseFormItem & {
514514
value: string;
515515
label: string;
516516
}>;
517+
disabled?: boolean;
517518
};
518519

519520
type Stars = BaseFormItem & {

0 commit comments

Comments
 (0)