Skip to content

Commit bc75a12

Browse files
committed
Allow onChange for custom elements
- onChange from custom elements are now merged with the existing form onChange
1 parent 146e054 commit bc75a12

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

package/src/form/form.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,9 @@ const ZenstackFormInputInternal = (props: ZenstackFormInputProps) => {
581581
const handleChange = (event: any) => {
582582
const fieldName = props.field.name;
583583

584+
// Call custom element's onChange if it exists
585+
if (props.customElement?.props.onChange) props.customElement.props.onChange(event);
586+
584587
// Call original onChange
585588
props.form.getInputProps(fieldName).onChange(event);
586589

@@ -619,9 +622,10 @@ const ZenstackFormInputInternal = (props: ZenstackFormInputProps) => {
619622

620623
// Filter out props that are already defined in customElement
621624
const finalProps = Object.fromEntries(
622-
Object.entries(baseProps).filter(([key]) =>
623-
props.customElement!.props[key] === undefined,
624-
),
625+
Object.entries(baseProps).filter(([key]) => {
626+
if (key === 'onChange') return true; // Don't override onChange
627+
return props.customElement!.props[key] === undefined;
628+
}),
625629
);
626630
// For custom elements, we need to prioritize the loading placeholder
627631
if (props.isLoadingInitialData) finalProps.placeholder = LOADING_PLACEHOLDER;

0 commit comments

Comments
 (0)