fix: foreignKey, targetKey, sourceKey support filtering by Chinese characters (#5997)

This commit is contained in:
Katherine 2025-01-07 10:05:03 +08:00 committed by GitHub
parent bea3ebccc4
commit b4ed765317
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -149,6 +149,7 @@ export const SourceKey = observer(
defaultValue={sourceKey || options?.[0]?.value}
onChange={props?.onChange}
showSearch
filterOption={(input, option) => option?.label.toLowerCase().includes(input.toLowerCase())}
/>
</div>
);
@ -216,6 +217,7 @@ export const TargetKey = observer(
}}
value={initialValue}
disabled={disabled}
filterOption={(input, option) => option?.label.toLowerCase().includes(input.toLowerCase())}
/>
</div>
);
@ -235,6 +237,7 @@ export const ForeignKey = observer(
const compile = useCompile();
const form = useForm();
const [initialValue, setInitialValue] = useState(value || (template === 'view' ? null : field.initialValue));
const [initialOptions, setInitialOptions] = useState([]);
useEffect(() => {
const effectField = ['belongsTo'].includes(type)
? collectionName
@ -254,6 +257,7 @@ export const ForeignKey = observer(
};
});
setOptions(sourceOptions);
setInitialOptions(sourceOptions);
if (value) {
const option = sourceOptions.find((v) => v.value === value);
setInitialValue(option?.label || value);
@ -295,6 +299,15 @@ export const ForeignKey = observer(
props?.onChange?.(value);
setInitialValue(option.label || value);
}}
onSearch={(value) => {
if (value) {
const targetValue = value.toLocaleLowerCase();
const result = options.filter((v) => v.label.toLocaleLowerCase().includes(targetValue));
setOptions(result);
} else {
setOptions(initialOptions);
}
}}
/>
</div>
);