Skip to content

Commit

Permalink
fix dataset setting form validation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Büßemeyer authored and Michael Büßemeyer committed Dec 6, 2024
1 parent 6149a05 commit 6f58f26
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,9 @@ function SimpleLayerForm({
{
validator: syncValidator(
(value: string) =>
dataLayers.filter((someLayer: APIDataLayer) => someLayer.name === value)
.length <= 1,
form
.getFieldValue(["dataSource", "dataLayers"])
.filter((someLayer: APIDataLayer) => someLayer.name === value).length <= 1,
"Layer names must be unique.",
),
},
Expand Down
16 changes: 11 additions & 5 deletions frontend/javascripts/dashboard/dataset/dataset_settings_view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,18 @@ class DatasetSettingsView extends React.PureComponent<PropsWithFormAndRouter, St
this.state.activeDataSourceEditMode === "simple" ? "advanced" : "simple",
);

const afterForceUpdateCallback = () =>
const afterForceUpdateCallback = () => {
// Trigger validation manually, because fields may have been updated
form
.validateFields()
.then((formValues) => this.submit(formValues))
.catch((errorInfo) => this.handleValidationFailed(errorInfo));
// and defer the validation as it is done asynchronously by antd or so.
setTimeout(
() =>
form
.validateFields()
.then((formValues) => this.submit(formValues))
.catch((errorInfo) => this.handleValidationFailed(errorInfo)),
1,
);
};

// Need to force update of the SimpleAdvancedDataForm as removing a layer in the advanced tab does not update
// the form items in the simple tab (only the values are updated). The form items automatically update once
Expand Down

0 comments on commit 6f58f26

Please sign in to comment.