2020-06-05 18:06:52 +08:00
|
|
|
import { InternalNamePath } from './interface';
|
2019-07-03 20:14:39 +08:00
|
|
|
|
2021-12-12 14:58:49 +08:00
|
|
|
// 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';
|
|
|
|
|
2019-07-03 20:14:39 +08:00
|
|
|
export function toArray<T>(candidate?: T | T[] | false): T[] {
|
|
|
|
if (candidate === undefined || candidate === false) return [];
|
|
|
|
|
|
|
|
return Array.isArray(candidate) ? candidate : [candidate];
|
|
|
|
}
|
2019-07-04 15:00:11 +08:00
|
|
|
|
|
|
|
export function getFieldId(namePath: InternalNamePath, formName?: string): string | undefined {
|
|
|
|
if (!namePath.length) return undefined;
|
|
|
|
|
|
|
|
const mergedId = namePath.join('_');
|
2021-12-12 14:58:49 +08:00
|
|
|
|
|
|
|
if (formName) {
|
|
|
|
return `${formName}_${mergedId}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
const isIllegalName = formItemNameBlackList.indexOf(mergedId) >= 0;
|
|
|
|
|
|
|
|
return isIllegalName ? `${defaultItemNamePrefixCls}_${mergedId}` : mergedId;
|
2019-07-04 15:00:11 +08:00
|
|
|
}
|