Skip to content

Constants and utilities

  • FaMimeType contains MIME constants used by upload APIs.
  • RegExps contains shared validators for mainland Chinese mobile numbers, email, password strengths, six-digit verification codes, four-character image codes, and other common values.
  • Decimal reexports decimal.js for upload progress and application calculations.

formUtil.validate Validate

Validates an entire mounted ElForm.

Signature

ts
validate(ref: Readonly<Ref<FormInstance | null | undefined>>): FormValidationResult;

Example

ts
import { ref } from "vue";
import { formUtil } from "fast-element-plus";
import type { FormInstance } from "element-plus";

const formRef = ref<FormInstance>();
const result = await formUtil.validate(formRef);

Input

InputTypeRequired / defaultDescription
refReadonly<Ref<FormInstance | null | undefined>>RequiredElForm instance ref.

Returns

ValueTypeDescription
resultFormValidationResultResolves true when valid; rejects with invalidFields when invalid or Error when unmounted.

formUtil.validateScrollToField Validate

Validates the form and scrolls to an invalid field on failure.

Signature

ts
validateScrollToField(ref: Readonly<Ref<FormInstance | null | undefined>>): FormValidationResult;

Example

ts
const result = await formUtil.validateScrollToField(formRef);

Input

InputTypeRequired / defaultDescription
refReadonly<Ref<FormInstance | null | undefined>>RequiredElForm instance ref.

Returns

ValueTypeDescription
resultFormValidationResultResolves true when valid; otherwise scrolls and rejects with invalidFields.

formUtil.mobile Validate

Element Plus rule callback validating a required mainland Chinese mobile number.

Signature

ts
mobile(rule: FormItemRule, value: string, callback: (error?: Error) => void): void;

Example

ts
formUtil.mobile({} as FormItemRule, "13800138000", (error) => {
	if (error) console.error(error.message);
});

Input

InputTypeRequired / defaultDescription
ruleFormItemRuleRequiredRule object supplied by Element Plus; this validator does not read its fields.
valuestringRequiredRequired mainland Chinese mobile number to validate.
callback(error?: Error) => voidRequiredCalled without arguments on success or with Error on failure.

Returns

ValueTypeDescription
resultvoidNo return value; reports validation through callback.

formUtil.phone Validate

Element Plus rule callback validating an optional landline number.

Signature

ts
phone(rule: FormItemRule, value: string, callback: (error?: Error) => void): void;

Example

ts
formUtil.phone({} as FormItemRule, "010-12345678", (error) => {
	if (error) console.error(error.message);
});

Input

InputTypeRequired / defaultDescription
ruleFormItemRuleRequiredRule object supplied by Element Plus; this validator does not read its fields.
valuestringRequiredOptional landline number to validate.
callback(error?: Error) => voidRequiredCalled without arguments on success or with Error on failure.

Returns

ValueTypeDescription
resultvoidNo return value; reports validation through callback.

formUtil.email Validate

Element Plus rule callback validating an optional email address.

Signature

ts
email(rule: FormItemRule, value: string, callback: (error?: Error) => void): void;

Example

ts
formUtil.email({} as FormItemRule, "user@example.com", (error) => {
	if (error) console.error(error.message);
});

Input

InputTypeRequired / defaultDescription
ruleFormItemRuleRequiredRule object supplied by Element Plus; this validator does not read its fields.
valuestringRequiredOptional email address to validate.
callback(error?: Error) => voidRequiredCalled without arguments on success or with Error on failure.

Returns

ValueTypeDescription
resultvoidNo return value; reports validation through callback.

formUtil.idCard Validate

Element Plus rule callback validating an optional identity-card number.

Signature

ts
idCard(rule: FormItemRule, value: string, callback: (error?: Error) => void): void;

Example

ts
formUtil.idCard({} as FormItemRule, "11010519491231002X", (error) => {
	if (error) console.error(error.message);
});

Input

InputTypeRequired / defaultDescription
ruleFormItemRuleRequiredRule object supplied by Element Plus; this validator does not read its fields.
valuestringRequiredOptional identity-card number to validate.
callback(error?: Error) => voidRequiredCalled without arguments on success or with Error on failure.

Returns

ValueTypeDescription
resultvoidNo return value; reports validation through callback.

formUtil.carNumber Validate

Element Plus rule callback validating a seven- or eight-character license plate.

Signature

ts
carNumber(rule: FormItemRule, value: string | null | undefined, callback: (error?: Error) => void): void;

Example

ts
formUtil.carNumber({} as FormItemRule, "京A12345", (error) => {
	if (error) console.error(error.message);
});

Input

InputTypeRequired / defaultDescription
ruleFormItemRuleRequiredRule object supplied by Element Plus; this validator does not read its fields.
valuestring | null | undefinedRequiredSeven- or eight-character license plate to validate.
callback(error?: Error) => voidRequiredCalled without arguments on success or with Error on failure.

Returns

ValueTypeDescription
resultvoidNo return value; reports validation through callback.

formUtil.editorRequired Validate

Element Plus rule callback validating required rich text.

Signature

ts
editorRequired(rule: FormItemRule, value: string, callback: (error?: Error) => void): void;

Example

ts
formUtil.editorRequired({} as FormItemRule, "<p>正文</p>", (error) => {
	if (error) console.error(error.message);
});

Input

InputTypeRequired / defaultDescription
ruleFormItemRuleRequiredRule object supplied by Element Plus; this validator does not read its fields.
valuestringRequiredRequired rich-text value to validate.
callback(error?: Error) => voidRequiredCalled without arguments on success or with Error on failure.

Returns

ValueTypeDescription
resultvoidNo return value; reports validation through callback.

formUtil.external Validate

Element Plus rule callback validating an external link.

Signature

ts
external(rule: FormItemRule, value: string, callback: (error?: Error) => void): void;

Example

ts
formUtil.external({} as FormItemRule, "https://example.com", (error) => {
	if (error) console.error(error.message);
});

Input

InputTypeRequired / defaultDescription
ruleFormItemRuleRequiredRule object supplied by Element Plus; this validator does not read its fields.
valuestringRequiredExternal link to validate.
callback(error?: Error) => voidRequiredCalled without arguments on success or with Error on failure.

Returns

ValueTypeDescription
resultvoidNo return value; reports validation through callback.

formUtil.url Validate

Element Plus rule callback validating a URL.

Signature

ts
url(rule: FormItemRule, value: string, callback: (error?: Error) => void): void;

Example

ts
formUtil.url({} as FormItemRule, "https://example.com/path", (error) => {
	if (error) console.error(error.message);
});

Input

InputTypeRequired / defaultDescription
ruleFormItemRuleRequiredRule object supplied by Element Plus; this validator does not read its fields.
valuestringRequiredURL to validate.
callback(error?: Error) => voidRequiredCalled without arguments on success or with Error on failure.

Returns

ValueTypeDescription
resultvoidNo return value; reports validation through callback.

formUtil.postCode Validate

Element Plus rule callback validating a postal code.

Signature

ts
postCode(rule: FormItemRule, value: string, callback: (error?: Error) => void): void;

Example

ts
formUtil.postCode({} as FormItemRule, "100000", (error) => {
	if (error) console.error(error.message);
});

Input

InputTypeRequired / defaultDescription
ruleFormItemRuleRequiredRule object supplied by Element Plus; this validator does not read its fields.
valuestringRequiredPostal code to validate.
callback(error?: Error) => voidRequiredCalled without arguments on success or with Error on failure.

Returns

ValueTypeDescription
resultvoidNo return value; reports validation through callback.

formUtil.account Validate

Element Plus rule callback validating a 6–20-character account.

Signature

ts
account(rule: FormItemRule, value: string, callback: (error?: Error) => void): void;

Example

ts
formUtil.account({} as FormItemRule, "fast123", (error) => {
	if (error) console.error(error.message);
});

Input

InputTypeRequired / defaultDescription
ruleFormItemRuleRequiredRule object supplied by Element Plus; this validator does not read its fields.
valuestringRequired6–20-character account to validate.
callback(error?: Error) => voidRequiredCalled without arguments on success or with Error on failure.

Returns

ValueTypeDescription
resultvoidNo return value; reports validation through callback.

formUtil.password Validate

Element Plus rule callback validating a 6–18-character weak password.

Signature

ts
password(rule: FormItemRule, value: string, callback: (error?: Error) => void): void;

Example

ts
formUtil.password({} as FormItemRule, "fast1234", (error) => {
	if (error) console.error(error.message);
});

Input

InputTypeRequired / defaultDescription
ruleFormItemRuleRequiredRule object supplied by Element Plus; this validator does not read its fields.
valuestringRequired6–18-character weak password to validate.
callback(error?: Error) => voidRequiredCalled without arguments on success or with Error on failure.

Returns

ValueTypeDescription
resultvoidNo return value; reports validation through callback.

formUtil.strongPassword Validate

Element Plus rule callback validating an 8–20-character strong password.

Signature

ts
strongPassword(rule: FormItemRule, value: string, callback: (error?: Error) => void): void;

Example

ts
formUtil.strongPassword({} as FormItemRule, "Fast@1234", (error) => {
	if (error) console.error(error.message);
});

Input

InputTypeRequired / defaultDescription
ruleFormItemRuleRequiredRule object supplied by Element Plus; this validator does not read its fields.
valuestringRequired8–20-character strong password to validate.
callback(error?: Error) => voidRequiredCalled without arguments on success or with Error on failure.

Returns

ValueTypeDescription
resultvoidNo return value; reports validation through callback.

formUtil.chinese Validate

Element Plus rule callback validating Chinese characters.

Signature

ts
chinese(rule: FormItemRule, value: string, callback: (error?: Error) => void): void;

Example

ts
formUtil.chinese({} as FormItemRule, "中文", (error) => {
	if (error) console.error(error.message);
});

Input

InputTypeRequired / defaultDescription
ruleFormItemRuleRequiredRule object supplied by Element Plus; this validator does not read its fields.
valuestringRequiredChinese characters to validate.
callback(error?: Error) => voidRequiredCalled without arguments on success or with Error on failure.

Returns

ValueTypeDescription
resultvoidNo return value; reports validation through callback.

formUtil.english Validate

Element Plus rule callback validating English characters.

Signature

ts
english(rule: FormItemRule, value: string, callback: (error?: Error) => void): void;

Example

ts
formUtil.english({} as FormItemRule, "Fast", (error) => {
	if (error) console.error(error.message);
});

Input

InputTypeRequired / defaultDescription
ruleFormItemRuleRequiredRule object supplied by Element Plus; this validator does not read its fields.
valuestringRequiredEnglish characters to validate.
callback(error?: Error) => voidRequiredCalled without arguments on success or with Error on failure.

Returns

ValueTypeDescription
resultvoidNo return value; reports validation through callback.

formUtil.inputRequired Validate

Creates a required text-input rule.

Signature

ts
inputRequired(message: string, trigger?: string): FormItemRule;

Example

ts
const result = formUtil.inputRequired("此项必填", "blur");

Input

InputTypeRequired / defaultDescription
messagestringRequiredValidation failure message.
triggerstringOptional; defaults to blurValidation trigger event name.

Returns

ValueTypeDescription
resultFormItemRuleElement Plus rule object with required, message, and trigger.

formUtil.selectRequired Validate

Creates a required-selection rule.

Signature

ts
selectRequired(message: string, trigger?: string): FormItemRule;

Example

ts
const result = formUtil.selectRequired("此项必填", "change");

Input

InputTypeRequired / defaultDescription
messagestringRequiredValidation failure message.
triggerstringOptional; defaults to changeValidation trigger event name.

Returns

ValueTypeDescription
resultFormItemRuleElement Plus rule object with required, message, and trigger.

tableUtil.formatValue Format

Joins array cell values as text and normalizes empty arrays.

Signature

ts
formatValue(value: unknown): unknown;

Example

ts
const result = tableUtil.formatValue(["A", "B"]);

Input

InputTypeRequired / defaultDescription
valueunknownRequiredCurrent cell value.

Returns

ValueTypeDescription
resultunknownJoined array text, null for empty arrays, or the original nonarray value.

tableUtil.handleRowAccordingToProp Value

Reads a nested row field using a dotted path.

Signature

ts
handleRowAccordingToProp(row: DefaultRow, prop: string): unknown;

Example

ts
const result = tableUtil.handleRowAccordingToProp({ user: { name: "Fast" } }, "user.name");

Input

InputTypeRequired / defaultDescription
rowDefaultRowRequiredCurrent table row.
propstringRequiredField name or dotted path.

Returns

ValueTypeDescription
resultunknownTarget field value, or undefined when traversal fails.

tableUtil.handleProp Value

Gets the final segment of a dotted field path.

Signature

ts
handleProp(prop: string): string;

Example

ts
const result = tableUtil.handleProp("user.name");

Input

InputTypeRequired / defaultDescription
propstringRequiredField path.

Returns

ValueTypeDescription
resultstringFinal field name.

tableUtil.filterEnum Enum

Looks up a label or tag type in table enum options.

Signature

ts
filterEnum(value: unknown, enumData: FaTableEnumColumnCtx[], fieldNames?: { label: string; value: string }, type?: "tag"): unknown;

Example

ts
const result = tableUtil.filterEnum(1, [{ label: "启用", value: 1, type: "success" }]);

Input

InputTypeRequired / defaultDescription
valueunknownRequiredCurrent cell value.
enumDataFaTableEnumColumnCtx[]RequiredCandidate enum options.
fieldNames{ label: string; value: string }OptionalCustom label and value fields.
type"tag"OptionalReturns the enum tag type when tag is supplied.

Returns

ValueTypeDescription
resultunknownMatching label/tag type, or null/info when unmatched.

tableUtil.arrayDynamicSort Sort

Creates a multi-field comparator from pagination sort conditions.

Signature

ts
arrayDynamicSort(sortList: PagedSortInput[]): (a: DefaultRow, b: DefaultRow) => number;

Example

ts
const compare = tableUtil.arrayDynamicSort([{ enField: "name", mode: "ascending" }]);
const result = rows.toSorted(compare);

Input

InputTypeRequired / defaultDescription
sortListPagedSortInput[]RequiredFields and ascending/descending conditions in priority order.

Returns

ValueTypeDescription
result(a: DefaultRow, b: DefaultRow) => numberComparator accepted by Array sorting methods.

tableUtil.setEnumMap Enum

Writes static or factory enum options into the table enum Map.

Signature

ts
setEnumMap(columnEnum: FaTableEnumColumnType, prop: string, enumMap: Map<string, FaTableEnumColumnCtx[]>): void;

Example

ts
const enumMap = new Map();
tableUtil.setEnumMap([{ label: "启用", value: 1 }], "status", enumMap);

Input

InputTypeRequired / defaultDescription
columnEnumFaTableEnumColumnTypeRequiredEnum name, options array, or options factory.
propstringRequiredColumn field key used by the Map.
enumMapMap<string, FaTableEnumColumnCtx[]>RequiredTable enum Map to update.

Returns

ValueTypeDescription
resultvoidNo return value.

tableUtil.flatColumns Flatten

Recursively flattens table columns, optionally collecting enum options.

Signature

ts
flatColumns(columns: FaTableColumnCtx[], enumMap?: Map<string, FaTableEnumColumnCtx[]>): FaTableColumnCtx[];

Example

ts
const result = tableUtil.flatColumns(columns, new Map());

Input

InputTypeRequired / defaultDescription
columnsFaTableColumnCtx[]RequiredColumn tree potentially containing _children.
enumMapMap<string, FaTableEnumColumnCtx[]>OptionalEnum Map to populate.

Returns

ValueTypeDescription
resultFaTableColumnCtx[]Flattened array containing leaf columns only.