mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-01 23:29:30 +08:00
34dbf5f0a2
* Form.Item的name属性改为parentNode,dom-align 死循环,内存溢出的bug * Form.Item的name属性改为parentNode,dom-align 死循环,内存溢出的bug * fixed lint issues. * change: add black list for form item name * keep the definition the same as before * update snapshot * change formItemNameBlackList type to array * add test case for form item is in black list * add test condition * prettier it * change: add black list for form item name * keep the definition the same as before * merege from upstream * rebase this branch * change formItemNameBlackList type to array * add test case for form item is in black list * add test condition * prettier it * fix test case that casing by rebase
29 lines
937 B
TypeScript
29 lines
937 B
TypeScript
import { 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.indexOf(mergedId) >= 0;
|
|
|
|
return isIllegalName ? `${defaultItemNamePrefixCls}_${mergedId}` : mergedId;
|
|
}
|