Skip to content

Commit 04d3fdb

Browse files
committed
Fix - Autocomplete field not showing validation error
1 parent cbfc8f8 commit 04d3fdb

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

geonode_mapstore_client/client/js/components/Autocomplete/Autocomplete.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const IconWithTooltip = tooltip((props) => <div {...props}><FaIcon name="info-ci
2121
const Autocomplete = ({
2222
className,
2323
description,
24+
error,
2425
helpTitleIcon,
2526
id,
2627
labelKey = "label",
@@ -44,7 +45,7 @@ const Autocomplete = ({
4445
};
4546

4647
return (
47-
<div className={`autocomplete${className ? " " + className : ""}`}>
48+
<div className={`autocomplete${className ? " " + className : ""}${!!error ? " " + "has-error" : ""}`}>
4849
<div className="title-container">
4950
<label className="control-label" htmlFor={id}>{title || name}</label>
5051
{helpTitleIcon && !isEmpty(description) && <IconWithTooltip className="help-title" tooltip={description} tooltipPosition={"right"} />}
@@ -56,13 +57,15 @@ const Autocomplete = ({
5657
valueKey={valueKey}
5758
labelKey={labelKey}
5859
/>
60+
{error}
5961
</div>
6062
);
6163
};
6264

6365
Autocomplete.propTypes = {
6466
className: PropTypes.string,
6567
description: PropTypes.string,
68+
error: PropTypes.element,
6669
helpTitleIcon: PropTypes.bool,
6770
id: PropTypes.string.isRequired,
6871
labelKey: PropTypes.string,

geonode_mapstore_client/client/js/plugins/MetadataEditor/components/_fields/SchemaField.jsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88

99
import React from 'react';
1010
import axios from '@mapstore/framework/libs/ajax';
11-
import isString from 'lodash/isString';
11+
import isArray from 'lodash/isArray';
1212
import isEmpty from 'lodash/isEmpty';
13+
import isString from 'lodash/isString';
14+
import get from 'lodash/get';
1315
import Autocomplete from '@js/components/Autocomplete/Autocomplete';
1416
import DefaultSchemaField from '@rjsf/core/lib/components/fields/SchemaField';
1517

@@ -26,6 +28,8 @@ const SchemaField = (props) => {
2628
formData,
2729
idSchema,
2830
name,
31+
hideError,
32+
errorSchema,
2933
uiSchema
3034
} = props;
3135
const autocomplete = uiSchema?.['ui:options']?.['geonode-ui:autocomplete'];
@@ -37,6 +41,9 @@ const SchemaField = (props) => {
3741
const isSingleSelect = schema?.type === 'object' && !isEmpty(schema?.properties);
3842

3943
if (autocomplete && (isMultiSelect || isSingleSelect)) {
44+
const errors = !hideError ? isArray(errorSchema)
45+
? errorSchema.map(error => get(error, 'id.__errors', [])).flat()
46+
: get(errorSchema, '__errors', []) : [];
4047
const autocompleteOptions = isString(autocomplete)
4148
? { url: autocomplete }
4249
: autocomplete;
@@ -104,7 +111,16 @@ const SchemaField = (props) => {
104111
})
105112
};
106113
});
107-
}
114+
},
115+
error: isEmpty(errors) ? null : <ul>
116+
{errors.map((error, idx) => {
117+
return (
118+
<li key={idx} className="gn-error-message">
119+
{error}
120+
</li>
121+
);
122+
})}
123+
</ul>
108124
};
109125

110126
return <Autocomplete {...autoCompleteProps}/>;

geonode_mapstore_client/client/themes/geonode/less/_metadata.less

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,17 @@
1313
.border-color-var(@theme-vars[main-border-color]);
1414
}
1515
}
16-
.gn-metadata-groups .gn-metadata-group > .field-object {
17-
.border-color-var(@theme-vars[main-border-color]);
16+
.gn-metadata-groups {
17+
.gn-metadata-group {
18+
& > .field-object {
19+
.border-color-var(@theme-vars[main-border-color]);
20+
}
21+
.has-error {
22+
label, .help-title, .gn-error-message, .gn-metadata-form-description {
23+
.color-var(@theme-vars[danger])
24+
}
25+
}
26+
}
1827
}
1928
.gn-metadata-list {
2029
.border-right-color-var(@theme-vars[main-border-color]);

0 commit comments

Comments
 (0)