Skip to content

Commit

Permalink
fix: trigger type in Rule
Browse files Browse the repository at this point in the history
  • Loading branch information
eternalsky committed Sep 23, 2024
1 parent 3edbf23 commit 2f6e5e5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@alifd/field",
"version": "2.0.2",
"version": "2.0.3",
"description": "Fields can be used to manage data when it comes to form data manipulation and validation. After being associated with a component, the form data can be automatically written back, read, and verified.",
"files": [
"demo/",
Expand Down Expand Up @@ -93,7 +93,7 @@
"表单"
]
},
"homepage": "https://unpkg.com/@alifd/field@2.0.2/build/index.html",
"homepage": "https://unpkg.com/@alifd/field@2.0.3/build/index.html",
"bugs": "https://github.com/alibaba-fusion/field/issues",
"publishConfig": {
"access": "public",
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class Field {
: field.value,
};

let rulesMap: Record<string, Omit<Rule, 'trigger'>[]> = {};
let rulesMap: Record<string, Rule[]> = {};

if (this.options.autoValidate && autoValidate !== false) {
// trigger map in rules,
Expand Down Expand Up @@ -1165,7 +1165,7 @@ class Field {
}
}

_validate(name: string, rule: Omit<Rule, 'trigger'>[], trigger: string) {
_validate(name: string, rule: Rule[], trigger: string) {
const field = this._get(name);
if (!field) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export type Rule = {
/**
* 触发校验的事件名称
*/
trigger?: 'onChange' | 'onBlur' | string;
trigger?: string | string[];
};

export type InitOption<
Expand Down
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export function getValueFromEvent(e: unknown) {
}

function validateMap<Rule extends { trigger?: string | string[]; [key: string]: unknown }>(
rulesMap: Record<string, Omit<Rule, 'trigger'>[]>,
rulesMap: Record<string, Rule[]>,
rule: Rule,
defaultTrigger: string
) {
Expand Down Expand Up @@ -281,7 +281,7 @@ export function mapValidateRules<Rule extends { [key: string]: unknown; trigger?
rules: Rule[],
defaultTrigger: string
) {
const rulesMap: Record<string, Array<Omit<Rule, 'trigger'>>> = {};
const rulesMap: Record<string, Array<Rule>> = {};

rules.forEach((rule) => {
validateMap(rulesMap, rule, defaultTrigger);
Expand Down

0 comments on commit 2f6e5e5

Please sign in to comment.