-
Notifications
You must be signed in to change notification settings - Fork 13
fix(DBCustomSelect): form reset functionality #4853
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
60de8b1
ad57a0b
65f7a3b
e7d5d09
54b317a
a447b50
d89a1dc
2fd9b3a
b7eac5c
2e2113b
fc8bc74
03315e4
4c97b02
61a7598
f960b05
1873988
714b2e3
2a61cb4
91f82d6
c1ffca3
aba2e6b
a34412a
e6b5701
60530f9
f046112
9d90943
80bc04a
7b610f8
5bb09ba
3970c78
83466ad
99ea02f
ca3459e
d4df627
97beaa5
a8d4e1c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| --- | ||
| "@db-ux/core-components": patch | ||
| "@db-ux/ngx-core-components": patch | ||
| "@db-ux/react-core-components": patch | ||
| "@db-ux/v-core-components": patch | ||
| "@db-ux/wc-core-components": patch | ||
| --- | ||
|
|
||
| fix(DBCustomSelect): automatically handle form reset events | ||
|
|
||
| An event listener is now added for every form component (input, custom-select, etc.) when a `form` property is passed. | ||
| This listener detects form resets and updates the component's internal value/checked state accordingly. | ||
|
|
||
nmerget marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| > **Note**: This does not work for `ngModel` in Angular. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,7 @@ import { DocumentClickListener } from '../../utils/document-click-listener'; | |
| import { DocumentScrollListener } from '../../utils/document-scroll-listener'; | ||
| import { handleFixedDropdown } from '../../utils/floating-components'; | ||
| import { | ||
| addResetEventListener, | ||
| handleFrameworkEventAngular, | ||
| handleFrameworkEventVue | ||
| } from '../../utils/form-components'; | ||
|
|
@@ -750,6 +751,21 @@ export default function DBCustomSelect(props: DBCustomSelectProps) { | |
| } | ||
| }, [state._values, selectRef]); | ||
|
|
||
| onUpdate(() => { | ||
| if (selectRef) { | ||
| const initialValues = props.values; | ||
| addResetEventListener(selectRef, () => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reset event listener is added here but never removed. This could lead to duplicate callbacks. |
||
| const resetValue = initialValues | ||
| ? initialValues | ||
| : selectRef.value | ||
| ? [selectRef.value] | ||
| : []; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently, the reset even clears the selection by setting _values = []. |
||
| state.handleOptionSelected(resetValue); | ||
| state.handleValidation(); | ||
| }); | ||
| } | ||
| }, [selectRef]); | ||
|
|
||
| onUpdate(() => { | ||
| state._validity = props.validation; | ||
| }, [props.validation]); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.