Skip to content
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

Fix - Autocomplete field not showing validation error #1912

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const IconWithTooltip = tooltip((props) => <div {...props}><FaIcon name="info-ci
const Autocomplete = ({
className,
description,
error,
helpTitleIcon,
id,
labelKey = "label",
Expand All @@ -44,7 +45,7 @@ const Autocomplete = ({
};

return (
<div className={`autocomplete${className ? " " + className : ""}`}>
<div className={`autocomplete${className ? " " + className : ""}${!!error ? " " + "has-error" : ""}`}>
<div className="title-container">
<label className="control-label" htmlFor={id}>{title || name}</label>
{helpTitleIcon && !isEmpty(description) && <IconWithTooltip className="help-title" tooltip={description} tooltipPosition={"right"} />}
Expand All @@ -56,13 +57,15 @@ const Autocomplete = ({
valueKey={valueKey}
labelKey={labelKey}
/>
{error}
</div>
);
};

Autocomplete.propTypes = {
className: PropTypes.string,
description: PropTypes.string,
error: PropTypes.element,
helpTitleIcon: PropTypes.bool,
id: PropTypes.string.isRequired,
labelKey: PropTypes.string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

import React from 'react';
import axios from '@mapstore/framework/libs/ajax';
import isString from 'lodash/isString';
import isArray from 'lodash/isArray';
import isEmpty from 'lodash/isEmpty';
import isString from 'lodash/isString';
import get from 'lodash/get';
import Autocomplete from '@js/components/Autocomplete/Autocomplete';
import DefaultSchemaField from '@rjsf/core/lib/components/fields/SchemaField';

Expand All @@ -26,6 +28,8 @@ const SchemaField = (props) => {
formData,
idSchema,
name,
hideError,
errorSchema,
uiSchema
} = props;
const autocomplete = uiSchema?.['ui:options']?.['geonode-ui:autocomplete'];
Expand All @@ -37,6 +41,9 @@ const SchemaField = (props) => {
const isSingleSelect = schema?.type === 'object' && !isEmpty(schema?.properties);

if (autocomplete && (isMultiSelect || isSingleSelect)) {
const errors = !hideError ? isArray(errorSchema)
? errorSchema.map(error => get(error, 'id.__errors', [])).flat()
: get(errorSchema, '__errors', []) : [];
dsuren1 marked this conversation as resolved.
Show resolved Hide resolved
const autocompleteOptions = isString(autocomplete)
? { url: autocomplete }
: autocomplete;
Expand Down Expand Up @@ -104,7 +111,16 @@ const SchemaField = (props) => {
})
};
});
}
},
error: isEmpty(errors) ? null : <ul>
{errors.map((error, idx) => {
return (
<li key={idx} className="gn-error-message">
{error}
</li>
);
})}
</ul>
dsuren1 marked this conversation as resolved.
Show resolved Hide resolved
};

return <Autocomplete {...autoCompleteProps}/>;
Expand Down
13 changes: 11 additions & 2 deletions geonode_mapstore_client/client/themes/geonode/less/_metadata.less
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,17 @@
.border-color-var(@theme-vars[main-border-color]);
}
}
.gn-metadata-groups .gn-metadata-group > .field-object {
.border-color-var(@theme-vars[main-border-color]);
.gn-metadata-groups {
.gn-metadata-group {
& > .field-object {
.border-color-var(@theme-vars[main-border-color]);
}
.has-error {
label, .help-title, .gn-error-message, .gn-metadata-form-description {
dsuren1 marked this conversation as resolved.
Show resolved Hide resolved
.color-var(@theme-vars[danger])
}
}
}
}
.gn-metadata-list {
.border-right-color-var(@theme-vars[main-border-color]);
Expand Down