Skip to content

Commit affac0e

Browse files
committed
feat(component): introduce onChange() prop
1 parent 3fe209f commit affac0e

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

lib/forms/component.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export type ApolloFormProps<T> = {
5454
subTitle?: string;
5555
config: ApolloFormConfig & { mutation?: { name: T } };
5656
onSave?: (data: object) => void;
57+
onChange?: (data: object) => void;
5758
onCancel?: () => void;
5859
ui?: UiSchema & ApolloFormUi;
5960
children?: React.SFC<ApolloRenderProps>;
@@ -252,13 +253,20 @@ export function configure<MutationNamesType = {}>(opts: ApolloFormConfigureOptio
252253
this.props.ui,
253254
data.formData
254255
);
255-
this.setState(() => ({
256-
isDirty: true,
257-
data: cleanData(data.formData, newSchema.properties),
258-
schemaWithConditionals: newSchema,
259-
hasError: data.errors.length > 0,
260-
isSaved: false
261-
}));
256+
this.setState(
257+
() => ({
258+
isDirty: true,
259+
data: cleanData(data.formData, newSchema.properties),
260+
schemaWithConditionals: newSchema,
261+
hasError: data.errors.length > 0,
262+
isSaved: false
263+
}),
264+
() => {
265+
if (this.props.onChange) {
266+
this.props.onChange(this.state.data);
267+
}
268+
}
269+
);
262270
}
263271

264272
simulateSubmit = () => {

0 commit comments

Comments
 (0)