mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-05 21:48:19 +08:00
28d1157d6b
* type: optimization undefined type * fix type * fix type * add * revert * revert * revert
31 lines
948 B
TypeScript
31 lines
948 B
TypeScript
import type { InternalNamePath } from './interface';
|
|
|
|
// form item name black list. in form ,you can use form.id get the form item element.
|
|
// use object hasOwnProperty will get better performance if black list is longer.
|
|
const formItemNameBlackList = ['parentNode'];
|
|
|
|
// default form item id prefix.
|
|
const defaultItemNamePrefixCls: string = 'form_item';
|
|
|
|
export function toArray<T>(candidate?: T | T[] | false): T[] {
|
|
if (candidate === undefined || candidate === false) return [];
|
|
|
|
return Array.isArray(candidate) ? candidate : [candidate];
|
|
}
|
|
|
|
export function getFieldId(namePath: InternalNamePath, formName?: string): string | undefined {
|
|
if (!namePath.length) {
|
|
return undefined;
|
|
}
|
|
|
|
const mergedId = namePath.join('_');
|
|
|
|
if (formName) {
|
|
return `${formName}_${mergedId}`;
|
|
}
|
|
|
|
const isIllegalName = formItemNameBlackList.includes(mergedId);
|
|
|
|
return isIllegalName ? `${defaultItemNamePrefixCls}_${mergedId}` : mergedId;
|
|
}
|