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